Course menuDVA-C03

Exams / DVA-C03 / Building APIs with API Gateway / Question 2

DVA-C03 practice question: Building APIs with API Gateway (2 of 2)

Development with AWS Services 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 payments team exposes a POST /refunds method in an Amazon API Gateway REST API, which invokes a Lambda function.

Every refund must include an orderId string and an amount number in its JSON body. Partner systems often send requests without amount, and each one currently runs the function, which fails and is billed.

The team wants API Gateway to return a 400 error for these requests without invoking the function.

Which TWO actions should the developer take? (Choose two.)

Choose two answers.

  1. A. Create a model with a JSON schema that lists orderId and amount as required properties.
  2. B. Add a mapping template to the integration request that removes any field that is empty.
  3. C. Attach a request validator that checks the body, and set the model on the method request.
  4. D. Create a usage plan with API keys and require an API key on the POST method.
  5. E. Turn on detailed CloudWatch metrics for the stage so that the failed requests can be counted.
Show the answer and explanation

Answers: A, C

  • A. Right: Correct. A model holds the JSON schema that the request body must match. Body validation checks each request against the schema's required properties.
  • B. Wrong: Mapping templates reshape the payload sent to the backend. They run after the method has accepted the request, so they cannot return a 400 response.
  • C. Right: Correct. A request validator with body validation turned on is assigned to the method. API Gateway then returns a 400 and fails the request before the integration request is made. Learn more: Set up basic request validation in API Gateway (opens in a new tab)
  • D. Wrong: Usage plans control which clients may call the API and how often. They do not inspect the request body, so bad requests still reach the function.
  • E. Wrong: Metrics show how often the problem happens but do not stop the requests. The function would still be invoked for each bad request.

Explanation

Body validation in API Gateway needs two parts: a model, which holds the JSON schema, and a request validator assigned to the method. A request that fails validation receives a 400 response from API Gateway, so the backend function is never invoked.

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 Building APIs with API Gateway? The 5 full-length practice sets have 10 more Building APIs with API Gateway questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets