Exams / DVA-C02 / Building APIs with API Gateway / Question 1
DVA-C02 practice question: Building APIs with API Gateway (1 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 REST API in Amazon API Gateway uses a Lambda custom (non-proxy) integration. When input is invalid, the function raises an error whose message starts with "InvalidInput:". Clients currently receive HTTP 200 with the error in the body. The developer wants these errors returned as HTTP 400. What should the developer configure?
Choose one answer.
- AA. Change the function to return a JSON object whose statusCode field is set to 400.
- BB. Add a 400 method response and a 400 integration response with selection pattern InvalidInput.*
- CC. Add a request validator to the method so that invalid input is rejected with a 400.
- DD. Add a gateway response for the BAD_REQUEST_BODY type that returns status code 400.
Show the answer and explanation
Answer: B
- A. Wrong: A statusCode field is honoured by Lambda proxy integrations. With a custom integration, API Gateway applies its own integration responses instead.
- B. Right: Correct. API Gateway matches the Lambda errorMessage against the selection pattern and returns the mapped status code, which must also exist as a method response.
- C. Wrong: A validator checks requests against a model. It cannot see the function's own business validation, which is what raises this error.
- D. Wrong: Gateway responses apply to errors API Gateway itself generates, such as failed validation, not to errors returned by the Lambda function.
Explanation
With Lambda custom integrations, Lambda errors are returned as 200 OK unless you map them. Each integration response has a selectionPattern regular expression that API Gateway tests against the error's errorMessage. A match returns the integration response's status code, and a method response for that code must also be defined, or API Gateway returns a configuration error.
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.