A REST API forwards requests to a Lambda function that raises errors whose text contains NotFound or Conflict. Clients should receive 404 or 409 respectively. The Lambda code must stay unchanged. Which configuration achieves this?
Show answer and explanation
Answer: D
With a non-proxy Lambda integration in a REST API, integration responses can use a selection pattern, a regular expression matched against the error message, to pick which HTTP status a method returns. Each pattern maps to a declared method response such as 404 or 409, and the function stays untouched. Proxy integration passes the function's own statusCode through, which would require changing the code. Separate resources and destinations do not translate errors into status codes.
Why the other options are wrong
- A. Proxy integration hands the status code to API Gateway from the function's return value. That requires editing the Lambda code, which the requirement rules out.
- B. Creating one resource per status code changes the URL structure and does not map the function's errors to the correct response codes.
- C. A Lambda destination routes the outcome of an asynchronous call to another target. It does not shape the synchronous HTTP response a client receives.