aws-sdk-js icon indicating copy to clipboard operation
aws-sdk-js copied to clipboard

"Missing config credentials" on first attempt

Open rodrigoreis22 opened this issue 12 years ago • 4 comments

I'm having this error while trying to upload an object to S3 on the FIRST attempt only. The second one goes through...

this is my method:

this.s3PutObject = function (file, bucketPath, onResponse, onHttpUploadProgress) { var bucket = new AWS.S3({ params: { Bucket: bucketPath } }); AWS.config.update({ accessKeyId: AAKID, secretAccessKey: SAK }); AWS.config.region = 'us-west-2';

  if (file) {
    // Perform File Size Check First
    var fileSize = Math.round(parseInt(file.size));
    if (fileSize > 2097152000) { //2GB file limit
      return onResponse('FILE_TOO_BIG');
    }
    // Prepend Unique String To Prevent Overwrites
    var uniqueFileName = uniqueString() + '-' + file.name;

    var params = { Key: uniqueFileName, ContentType: file.type, Body: file, ServerSideEncryption: 'AES256' };

    console.log('params: %s', JSON.stringify(params));

    bucket.putObject(params, function (err, data) {
      return onResponse(err, data);
    })
      .on('httpUploadProgress', onHttpUploadProgress);
  }
  else {
    onResponse('NO_FILE_SELECTED');
  }
};

rodrigoreis22 avatar Sep 13 '14 02:09 rodrigoreis22

Can you try updating credentials before constructing the service object?

AWS.config.update({ accessKeyId: AAKID, secretAccessKey: SAK });
AWS.config.region = 'us-west-2';
var bucket = new AWS.S3({ params: { Bucket: bucketPath } });

This is because credentials are sourced from AWS.config when constructing a service object.

Let me know if the error persists after making this change.

AdityaManohar avatar Sep 13 '14 10:09 AdityaManohar

That worked @AdityaManohar . Thanks!

rodrigoreis22 avatar Sep 13 '14 20:09 rodrigoreis22

Sure! I'm closing this as resolved.

AdityaManohar avatar Sep 15 '14 16:09 AdityaManohar

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

lock[bot] avatar Sep 30 '19 02:09 lock[bot]