Jesus is Lord
Jesus is Lord

Reputation: 15399

Why can't I access my S3 bucket from a Lambda function?

I have a lambda function.

Here's the code:

// ...
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.
    // ...
});
// ...

Here's what CloudWatch says:

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)'

My lambda function is associated with a custom role. That role has the AWSLambdaFullAccess policy attached, which includes full S3 access. Why can't I access the S3 bucket?

Upvotes: 0

Views: 388

Answers (1)

Jesus is Lord
Jesus is Lord

Reputation: 15399

In asking the question I noticed the bucket name I was providing was wrong. (the bucket belonged to another AWS account, which is why AWSLambdaFullAccess was insufficient.) That was the issue.

Upvotes: 1

Related Questions