AWS node.js SDK 获取 'Access Denied' 使用 AWS 示例

AWS node.js SDK getting 'Access Denied' using AWS example

我是 AWS 的新手,也许我遗漏了一些明显的东西,因此需要帮助。

我有 2 个版本的代码,唯一不同的是将桶作为 4 个字符的字符串与 5 个字符传递。从aws得到不同的回应。 这是为什么?

var AWS = require('aws-sdk');
var s3 = new AWS.S3(); 

s3.createBucket({Bucket: 'node4'}, function() {
  var params = {Bucket: 'node4', Key: 'myKey', Body: 'Hello!'};
  s3.putObject(params, function(err, data) {
      if (err)       
          console.log(err)     
      else
        console.log("Successfully uploaded data to myBucket/myKey");   
   });
});

运行 app.js:

➜  aws  node app.js
{ [AllAccessDisabled: All access to this object has been disabled]
  message: 'All access to this object has been disabled',
  code: 'AllAccessDisabled',
  region: null,
  time: Fri Feb 05 2016 20:45:11 GMT+0200 (IST),
  requestId: 'somerequestId',
  extendedRequestId: 'someextendedRequestId',
  statusCode: 403,
  retryable: false,
  retryDelay: 30 }

第二个密码:

var AWS = require('aws-sdk');
var s3 = new AWS.S3(); 

s3.createBucket({Bucket: 'node4e'}, function() {
  var params = {Bucket: 'node4e', Key: 'myKey', Body: 'Hello!'};
  s3.putObject(params, function(err, data) {
      if (err)       
          console.log(err)     
      else
        console.log("Successfully uploaded data to myBucket/myKey");   
   });
});

运行 app.js:

➜  aws  node app.js
Successfully uploaded data to myBucket/myKey

the only different is passing bucket as a 4 chars string vs 5 chars

实际上唯一的区别是您没有对名为 'node4' 的存储桶的写入权限,而您有对名为 'node4e' 的存储桶的访问权限。您是否检查过两个存储桶是否实际上已成功创建?我注意到您没有检查 createBucket() 调用中的错误,只是检查 putObject() 调用中的错误。

您使用的是相当通用的存储桶名称,如果失败的存储桶名称 'node4' 已被另一个 AWS 帐户使用,我不会感到惊讶。