Question 1 · choose 1
An AWS Lambda function in an AWS SAM project processes messages from an Amazon SQS queue. In the continuous integration build, before anything is deployed, the developer wants to run the function locally with a realistic SQS event payload without writing the JSON structure by hand. What should the developer do?
- ASave a private test event in the Lambda console and run it from the build
- BCreate a real queue, send messages to it, and let the event source mapping invoke the function
- CRun sam local start-api and send the message body to it with an HTTP client
- DGenerate a payload with sam local generate-event sqs and pass it to sam local invoke --event
Show the answer and why
ASave a private test event in the Lambda console and run it from the build
Incorrect
Console test events run against the deployed function, and a private test event is available only to the user who created it.
BCreate a real queue, send messages to it, and let the event source mapping invoke the function
Incorrect
That tests a deployed function with real AWS resources, which the build wants to avoid at this stage.
CRun sam local start-api and send the message body to it with an HTTP client
Incorrect
sam local start-api serves functions through a local HTTP server. The function would receive an HTTP request event, not an SQS event.
DGenerate a payload with sam local generate-event sqs and pass it to sam local invoke --event
Correct
sam local generate-event produces sample payloads for supported services, which can be edited and passed with --event to a local invocation.
SAM CLI generates realistic service events for local tests: generate-event for the payload, local invoke to run the function with it.
AWS documentation