Course menuDVA-C02

Exams / DVA-C02 / Testing in development environments / Question 1

DVA-C02 practice question: Testing in development environments (1 of 2)

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

A developer has an AWS SAM application with a function that is triggered when objects are uploaded to Amazon S3. Before deploying, the developer wants to run the function on a laptop with a realistic S3 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.
  2. B. Run sam local start-api and send an HTTP request containing the S3 event.
  3. C. Run sam local generate-event for S3, then sam local invoke with --event.
  4. D. Use the Lambda console's test feature against the local copy of the code.
Show the answer and explanation

Answer: C

  • A. Wrong: This deploys to AWS, which is what the developer wants to avoid before testing locally.
  • B. Wrong: start-api emulates API Gateway endpoints for HTTP functions. This function is triggered by S3, not by HTTP.
  • C. Right: Correct. generate-event produces a sample payload, and local invoke runs the function once in a local container with it.
  • D. Wrong: The console tests the deployed function in AWS, not code on the developer's machine.

Explanation

The SAM CLI runs functions locally in Docker containers. sam local generate-event creates sample payloads for event sources such as S3, SQS and API Gateway, and sam local invoke --event passes one to the function. Local tests do not check IAM permissions, so test in the cloud as well.

Study

Keep practising

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