Course menuDVA-C02

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

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

Development with AWS Services 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 a POST method in an Amazon API Gateway REST API that invokes a Lambda function. Many requests arrive with a missing "customerId" field in the JSON body, and each one invokes the function only to fail. The developer wants API Gateway to reject these requests with a 400 error 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 marks customerId as a required property.
  2. B. Add a mapping template to the integration request that removes empty fields.
  3. C. Attach a request validator that validates the body, and set the model on the method request.
  4. D. Create a usage plan with an API key and require the key on the method.
  5. E. Turn on detailed CloudWatch metrics for the stage to log the failed requests.
Show the answer and explanation

Answers: A, C

  • A. Right: Correct. The model describes the expected body, and body validation checks each request against it.
  • B. Wrong: Mapping templates transform the payload sent to the backend. They do not reject requests.
  • C. Right: Correct. With body validation turned on for the method, API Gateway returns 400 for a non-conforming request and never calls the integration.
  • D. Wrong: Usage plans control who can call the API and how often. They do not inspect the body.
  • E. Wrong: Metrics help you observe the problem but do not stop the requests reaching the function.

Explanation

API Gateway basic request validation needs two parts: a model (JSON schema) for the request body, and a request validator on the method that enables body validation. Failed requests get a 400 response straight from API Gateway, so the backend is not invoked.

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.