How to Test AWS Lambda Locally with S3 Events Using SAM CLI?
A developer is implementing an AWS Lambda function that will be invoked when an object is uploaded to Amazon S3. The developer wants to test the Lambda function in a local development machine before publishing the function to a production AWS account. Which solution will meet these requirements with the LEAST operational overhead?
Community Votes
100% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
This question tests your knowledge of local Lambda development tooling; the trap is confusing 'least operational overhead' with using the AWS Console, which cannot test local functions.
To test an AWS Lambda function locally with an S3 event trigger using the least operational overhead, use the AWS SAM CLI to generate a sample S3 event and invoke the function locally.
Many candidates choose D, believing the AWS Management Console offers the least overhead, but the Console cannot invoke a Lambda function running on a local development machine.
Community Discussion (5 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Understanding the Requirement
The developer needs to test an AWS Lambda function locally on their development machine, simulating an Amazon S3 event trigger. The key constraints are: the function runs locally (not in AWS), and the solution must have the LEAST operational overhead.
Why Option C is Correct
Option C leverages the AWS Serverless Application Model (SAM) CLI, which is specifically designed for local serverless development. The workflow is:
1. sam local start-lambda – Starts a local endpoint that emulates the AWS Lambda service.
2. sam local generate-event s3 put – Generates a realistic sample S3 put event JSON, eliminating the need to manually craft the event structure.
3. sam local invoke -e event.json <FunctionName> – Invokes the local Lambda function with the generated event.
This approach requires no AWS infrastructure, no manual JSON crafting, and uses purpose-built tooling that comes with the SAM CLI—making it the solution with the least operational overhead for local testing.
Why the Other Options Fail
- Option A suggests uploading an object to S3 and waiting for a local invocation. However, S3 cannot trigger a Lambda function running on a local machine. S3 event notifications only invoke Lambda functions deployed in AWS.
- Option B uses
aws lambda invoke, which calls a Lambda function deployed in AWS, not a local function. This does not satisfy the requirement of testing on a local development machine.
- Option D suggests using the AWS Management Console to test a local Lambda function. The Console can only invoke Lambda functions that exist in an AWS account—it has no capability to reach a function running on your local machine. This is the most common trap answer.
Community Insight
The community overwhelmingly supports Option C (86%). Commenters note that SAM CLI is the standard toolchain for local Lambda development and that the Console (Option D) is a common but incorrect choice because it cannot interact with local functions.
Official Reference
- https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-local-start-lambda.html
- https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-generate-event.html
- https://docs.aws.amazon.com/lambda/latest/dg/testing-functions.html
Exam Strategy
When an exam question specifies 'local development machine,' immediately eliminate any options that rely on AWS-hosted services (Console, S3 triggers, or aws lambda invoke against deployed functions). Then choose the tool specifically built for local serverless testing—in this case, the SAM CLI.
Related Analysis
Practice All DVA-C02 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DVA-C02 Practice Test →