1

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?

MapLion
  • 1,041
  • 1
  • 12
  • 38
  • 1
    Can you run it once in lambda, not locally, save `event` into CW logs, and then use that as a template for your local executions? – Marcin Dec 30 '20 at 09:47
  • That sounds plausible. Let me try that. I think to add further confusion, I am using the streaming handler and I wasn't sure how to get ahold of the event https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/java-basic/src/main/java/example/HandlerStream.java – MapLion Dec 30 '20 at 18:39
  • @Marcin Yeah, I think part of my problem is that using a streaming handler with an inputStream and outputStream while also using a {proxy+} with Java, it doesn't seem straight-forward on how to print that event out so I can see it in CloudWatch. I continue to get strange errors while trying to copy direct examples. – MapLion Jan 01 '21 at 00:07
  • 1
    What about [sam local generate-event](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-generate-event.html)? Maybe it has event that could be of use to you? – Marcin Jan 01 '21 at 01:09
  • @Marcin this certainly helped, thank you. I think it serves my needs for now. – MapLion Jan 05 '21 at 17:28
  • No problem. If you don't mind, I will post an answer for future reference. – Marcin Jan 05 '21 at 22:50

1 Answers1

1

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.

Marcin
  • 215,873
  • 14
  • 235
  • 294