I'm using an API-Gateway + Lambda combo to process a POST request. I'm using Node + Serverless Framework.
When I run serverless offline, I am able to send a POST request and have my data stored on an S3. But when I deploy it and run the same POST request, I get a "502 Internal Server Error" message. Because it works locally but not in production, I'm pretty sure I have some permission/config problems.
saveToS3(newData)
.then(result => {
callback(null, {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: "Successfully added data!"
});
})
.catch(e => callback(null, { statusCode: 500, body: JSON.stringify(e) }));
What I've checked:
- Response body is a string
- Include status code, body, response header in the response
- Using a callback pattern to return my response (see above)
What I haven't checked:
- One possible reason is that my API-gateway api doesn't have access to invoke the lambda function. How do I make that setting in the
serverless.ymlfile?
My yml:
service: myService
provider:
name: aws
runtime: nodejs12.x
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource: "arn:aws:s3:::myS3Bucket/*"
functions:
saveToS3:
handler: handler.saveToS3
events:
- http:
path: users
method: post
cors: true
plugins:
- serverless-offline
resources:
Resources:
NewResource:
Type: AWS::S3::Bucket
Properties:
BucketName: myS3Bucket


