How to generate a proper event.json for a lambda called from API Gateway to run it locally?

1.9k Views Asked by At

I have a an aws lambda that I would like to be able to invoke locally utilizing sam local invoke "MyFunction" -e event.json, but my event.json file never seems to be correct. For example, if my lambda connects to DynamoDB, I get an error like "The security token included in the request is invalid."

Is there a way to run a functional lambda in the cloud and generate/output the event.json (e.g. as if it were invoked from API Gateway) so that you can then use it locally?

1

There are 1 best solutions below

0
Marcin On

Based on the comments.

SAM has number of test events available for use from many different services, including api gateway and dynamodb.

The test events can be accessed using sam local generate-event command.