节点js中的AWS SDK javascript返回拒绝访问

时间:2016-08-04 12:20:56

标签: javascript node.js amazon-web-services amazon-s3 access-denied

当我试图列出我的所有桶时,它会按预期工作。那么我可以确保我的设置是正确的。 问题是当我尝试列出存储桶的内容时:

我在节点js中有一条路由/:bucket

app.get('/:bucket', function (req, res) {
    var bucket = req.params.bucket;
    var s3 = new AWS.S3();
    var params = {
        Bucket: 'bucket'
    };
    s3.listObjects(params, function (err, data) {
        if (err)
            console.log(err, err.stack); // an error occurred
        else
            console.log(data);           // successful response
    });
});

这不起作用,它返回拒绝访问。

以下是存储桶策略:

{
  "Id": "Policy...............",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt..........",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::my_bucket/*",
      "Principal": "*"
    }
  ]
}

这是我得到的错误:

{ [AccessDenied: Access Denied]
  message: 'Access Denied',
  code: 'AccessDenied',
  region: 'us-east-1',
  time: Thu Aug 04 2016 13:14:56 GMT+0100 (CET),
  requestId: '.............',
  extendedRequestId: '.............................................',
  cfId: undefined,
  statusCode: 403,
  retryable: false,
  retryDelay: ........... } 'AccessDenied: Access Denied\n    at Request.extractError (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/services/s3.js:524:35)\n    at Request.callListeners (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/sequential_executor.js:105:20)\n    at Request.emit (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/sequential_executor.js:77:10)\n    at Request.emit (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/request.js:661:14)\n    at Request.transition (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/request.js:22:10)\n    at AcceptorStateMachine.runTo (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/state_machine.js:14:12)\n    at /home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/state_machine.js:26:10\n    at Request.<anonymous> (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/request.js:38:9)\n    at Request.<anonymous> (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/request.js:663:12)\n    at Request.callListeners (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/sequential_executor.js:115:18)\n    at Request.emit (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/sequential_executor.js:77:10)\n    at Request.emit (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/request.js:661:14)\n    at Request.transition (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/request.js:22:10)\n    at AcceptorStateMachine.runTo (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/state_machine.js:14:12)\n    at /home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/state_machine.js:26:10\n    at Request.<anonymous> (/home/azouz/PFE/Docker/PBD/node_modules/aws-sdk/lib/request.js:38:9)'

0 个答案:

没有答案