aws-sdk putObject Access Denied Request.extractError

て烟熏妆下的殇ゞ 提交于 2020-01-17 05:59:46

问题


I have the following policy attached to the IAM user I am using.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1468642330000",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::elasticbeanstalk-ap-southeast-1-648213736065/documents/*"
            ]
        }
    ]
}

Problem is when I do something like:

return readFile(file.path)
  .then(function(buffer) {
    var s3obj = s3.putObject({
      Bucket: bucket,
      Key: `documents/${destFileName}`,
      Body: buffer
    });
    return s3obj.promise();
  });

I get:

AccessDenied: Access Denied

Whats wrong here?


Looks like when I use listBuckets, I get contents from my other S3 account. Seems like the way I configure the SDK is incorrect?


回答1:


Ok, I found the issue, looks like its using the [default] profile specified in the ~/.aws/credentials file.

I found that I need to configure AWS like this:

AWS.config = new AWS.Config({
  accessKeyId: appConfig.aws.accessId,
  secretAccessKey: appConfig.aws.secretKey,
  logger: process.stdout
});

I was originally setting

AWS.config.accessKeyId = ...


来源:https://stackoverflow.com/questions/38411915/aws-sdk-putobject-access-denied-request-extracterror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!