Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS s3 api error: specified bucket does not exist

I am using the node AWS SDK to save images to s3. I keep getting the following error despite the fact that the bucket exists and I have the right permissions:

{ [NoSuchBucket: The specified bucket does not exist]
  message: 'The specified bucket does not exist',
  code: 'NoSuchBucket',
  time: Tue Oct 21 2014 12:32:50 GMT-0400 (EDT),
  statusCode: 404,
  retryable: false }

My nodejs code:

var fs = require('fs');

var AWS = require('aws-sdk'); //AWS library (used to provide temp credectials to a front end user)
AWS.config.loadFromPath('./AWS_credentials.json'); //load aws credentials from the     authentication text file



var s3 = new AWS.S3();

fs.readFile(__dirname + '/image.jpg', function(err, data) {

var params = {
    Bucket: 'https://s3.amazonaws.com/siv.io',
    Key: 'something',
};

s3.putObject(params, function(err, data) {

    if (err) {

        console.log(err);

    } else {
        console.log("Successfully uploaded data to myBucket/myKey");
    }
});
});

I've also tried siv.io.s3-website-us-east-1.amazonaws.com for the bucket name. Can someone let me know what I'm going wrong? I can provide more info if necessary.

like image 980
SivaDotRender Avatar asked Oct 21 '14 16:10

SivaDotRender


1 Answers

The error is stating that bucket does not yet exist. By the looks of your code, the bucket name is not correct, which is why a file cannot be found. Either make the call createBucket() or create the bucket in your AWS console.

You might adding a file as well, instead of just making the API call. Check the AWS API docs for what to put where. Their docs are really good.

Here's what I do:

    var stream = fs.createReadStream( 'path/to/file' );
    stream.on( 'error', function( error ) {
      seriesCb( error );
    } );
    //TODO: Other useful options here would be MD5 hash in the `ContentMD5` field,
    s3.putObject( {
      "Bucket": 'siv.io',
      "Key": 'name_of/new_file',
      "ContentType": "application/pdf", //might not apply to you
      "Body": stream
    }, function( s3err, s3results ) {
      if ( s3err ) return console.log('Bad stuff. ' + s3err.toString() );
      console.log( "Saved to S3. uri:" + s3uri);
    } );
like image 110
clay Avatar answered Sep 21 '22 05:09

clay