Course menuDVA-C03

Exams / DVA-C03 / Testing and test automation / Question 1

DVA-C03 practice question: Testing and test automation (1 of 3)

Testing and Deployment A free question from our original DVA-C03 practice exam. Try it, then open the answer to see why each option is right or wrong.

Last verified against current AWS documentation ·How we write our questions

A developer has an AWS SAM application with a function that runs whenever an object is uploaded to an Amazon S3 bucket.

The function is one step in the team's order pipeline, and its handler reads the bucket and key from each event. Before deploying anything, the developer wants to run the function on a laptop with a realistic S3 upload event.

Which approach should the developer use?

Choose one answer.

  1. A. Run sam deploy to a test stack, then upload an object to the bucket and check the function's CloudWatch logs.
  2. B. sam local start-api runs a local HTTP endpoint for API Gateway-style events, so the developer can send requests to it.
  3. C. Run sam local generate-event s3 put to create a sample event, then sam local invoke with that event file.
  4. D. Invoke the function from the Lambda console's test feature, pointing it at a local copy of the code and a sample event.
Show the answer and explanation

Answer: C

  • A. Wrong: A test stack would work, but it deploys to AWS and uses cloud resources, which the developer wants to avoid before deploying. It does not test the function on the laptop.
  • B. Wrong: sam local start-api runs an HTTP endpoint for API Gateway-style events. An S3 notification is not an HTTP request, so the function would not receive a realistic S3 event.
  • C. Right: Correct. generate-event s3 put writes a sample object-created event that imitates the S3 notification. sam local invoke then runs the function in a local container with that event, and no AWS resources are needed. Learn more: Generate sample event payloads with sam local generate-event (opens in a new tab)
  • D. Wrong: The Lambda console runs functions in AWS, not on a laptop, and it cannot run local code. It does not meet the need to test locally before deploying.

Explanation

The SAM CLI runs a function locally in a container. sam local generate-event creates a realistic sample event for services such as S3, and passing that event to sam local invoke tests the handler with a realistic payload. Local runs do not check IAM permissions, so the function should also be tested in AWS.

Study

Keep practicing

Answer questions with a score at the end, or practice just this topic with the explanation after each one. No sign-up needed.

Want more on Testing and test automation? The 5 full-length practice sets have 12 more Testing and test automation questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets