AWS s3 api error: bucket specified does not exist

I am using node AWS SDK to save images to s3. I keep getting the following error even though the bucket exists and I have rights:

{ [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 also tried siv.io.s3-website-us-east-1.amazonaws.com for the bucket name. Can anyone let me know if I'm wrong? If necessary, I can provide additional information.

+3


source to share


1 answer


The error indicates that the bucket does not exist yet. From the looks of your code, the bucket name is incorrect, so the file cannot be found. Either make a call createBucket()

or create a bucket in the AWS console.

You can also add a file instead of just calling an API call. Check out the AWS API docs . Their papers are really good.



That's what I'm doing:

    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);
    } );

      

+5


source







All Articles