为什么我无法从Lambda函数访问我的S3存储桶?

时间:2018-05-03 13:56:22

标签: amazon-web-services amazon-s3 aws-lambda

我有一个lambda函数。

以下是代码:

// ...
var s3 = new AWS.S3();
// ...
var param = { 
    Bucket: /* ... */, 
    Key: /* ... */, 
    Body: /* ... */,
};
// ...
s3.upload(param, function(err, data) {
    if (err) {
        // From CloudWatch, this branch is entered.
        console.log(err, err.stack);
    } else {
        // ...
    }

    // From CloudWatch, this is executed.
    // ...
});
// ...

这是CloudWatch所说的:

2018-05-03T04:26:44.093Z    2f132f9c-4e8a-11e8-899d-1903b51869d3    { AccessDenied: Access Denied
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/services/s3.js:577:35)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
message: 'Access Denied',
code: 'AccessDenied',
region: null,
time: 2018-05-03T04:26:44.093Z,
requestId: '1E0B4264477F7E24',
extendedRequestId: 'npqxl9WWgNP+4kYl+Vqyo4paP4h1bCUhM3hmWEdJ5LWvCTxn6vNNyeA6WBaBHIfbG+vfEtDARkc=',
cfId: undefined,
statusCode: 403,
retryable: false,
retryDelay: 87.11716082726679 } 'AccessDenied: Access Denied\n at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/services/s3.js:577:35)\n at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)\n at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)\n at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)\n at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)\n at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)\n at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10\n at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)\n at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)\n at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:115:18)'

我的lambda函数与自定义角色相关联。该角色附加了AWSLambdaFullAccess策略,其中包括完整的S3访问权限。为什么我无法访问S3存储桶?

1 个答案:

答案 0 :(得分:1)

在提出问题时,我注意到我提供的存储桶名称是错误的。 (该存储桶属于另一个AWS账户,这就是AWSLambdaFullAccess不足的原因。)这就是问题所在。