Wednesday, 31 May 2017

Access key issue with aws-sdk S3 in production environment (Javascript)

I am using the AWS-SDK in order to storage my images from my webapp. Also, I am using Javascript and multer in order to make the manage of the process. When I call the API from my localhost (my local computer) in order to do my tests, all works fine. But when I upload my project to a Digital Ocean droplet, it always says the following error:

The AWS Access Key Id you provided does not exist in our records.

I have set my environment access key and the secret key in the file /etc/environment and when I execute the command printenv, I can see the variables listed.

I am using the same variables both in my local computer and in the server. Why AWS reject my request?

In advance thanks. Here is my code:

var s3 = new aws.S3({
  region: 'us-west-2',
  accessKeyId: config.aws.accessKey,
  secretAccessKey: config.aws.secretKey
})

var storage = multerS3({
  s3: s3,
  bucket: 'pos-lisa',
  acl: 'public-read',
  metadata: function (req, file, cb) {
    cb(null, {fieldName: file.fieldname})
  },
  key: function (req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now() + '.' + fileExt(file.originalname))
  }
})



via maoooricio

No comments:

Post a Comment