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.
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.
AA. Create a model with a JSON schema that lists orderId and amount as required properties.
BB. Add a mapping template to the integration request that removes any field that is empty.
CC. Attach a request validator that checks the body, and set the model on the method request.
DD. Create a usage plan with API keys and require an API key on the POST method.
EE. 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.
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.
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 →