Reputation: 512
I seem to be getting permission issues and can't find any SO answer to resolve this.
My Lambda function is simple (note -- I am using Babel to transpile):
import AWS from "aws-sdk";
import { success, failure} from "./libs/response-lib";
export async function main(event, context, callback) {
const s3 = new AWS.S3();
const params = {
Bucket: "mybucket",
};
try {
const result = await s3.listObjectsV2(params);
return success(result);
}
catch(e) {
return failure({ status: false, message: e })
}
}
When I deploy using Serverless and hit the endpoint it gives me, I get back a 500 error.
I have this included in my serverless.yml
file and have turned off "block all public access" for the S3 bucket itself but it seems like I am missing more?
iamRoleStatements:
- Effect: Allow
Action:
- s3:ListBucket
Resource: "arn:aws:s3:::mybucket"
Upvotes: 3
Views: 1598
Reputation: 512
Okay, so AWS' S3 methods are asynchronous, so I needed to have it return a promise:
.
.
.
const result = await s3.listObjectsV2(params).promise();
.
.
.
Upvotes: 1