阅读背景:

aws-sdk putObject访问被拒绝的Request.extractError

来源:互联网 

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

我对我正在使用的IAM用户附加了以下策略。

{
    "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?

看起来当我使用listBuckets时,我从其他S3帐户获取内容。好像我配置SDK的方式不正确?

1 个解决方案

#1


1  

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

好的,我发现了这个问题,看起来像使用〜/ .aws / credentials文件中指定的[default]配置文件。

I found that I need to configure AWS like this:

我发现我需要像这样配置AWS:

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

I was originally setting

我原来是在设置

AWS.config.accessKeyId = ...

分享到: