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?

  1. Upload an object to Amazon S3 by using the aws s3api put-object CLI command. Wait for the local Lambda invocation from the S3 event.
  2. Create a sample JSON text file for a put object S3 event. Invoke the Lambda function locally. Use the aws lambda invoke CLI command with the JSON file and Lambda function name as arguments.
  3. Use the sam local start-lambda CLI command to start Lambda. Use the sam local generate-event s3 put CLI command to create the Lambda test JSON file. Use the sam local invoke CLI command with the JSON file as the argument to invoke the Lambda function. Source Reference Answer
  4. Create a JSON string for the put object S3 event. In the AWS Management Console, use the JSON string to create a test event for the local Lambda function. Perform the test.

Community Votes

C
100%

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)

sqlquaker 👍 1 Selected: D
SAM is not involved in this application setting. Solution should use "LEAST operational overhead". How to test Lambda functions in the console: https://docs.aws.amazon.com/lambda/latest/dg/testing-functions.html
preachr 👍 1 Selected: C
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-local-start-lambda.html
albert_kuo 👍 2 Selected: C
sam local start-lambda sam local generate-event s3 put > event.json sam local invoke -e event.json <LambdaFunctionName>
65703c1 👍 1 Selected: C
C is the correct answer.
koltysh 👍 2 Selected: C
https://www.examtopics.com/discussions/amazon/view/96490-exam-aws-certified-developer-associate-topic-1-question-395/

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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

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 →

← Back to DVA-C02 Study Guide