A developer is configuring a GET method on a REST API in Amazon API Gateway using a Lambda custom integration (non-proxy integration). When the backend AWS Lambda function encounters an invalid input parameter, it returns an error with the message `InvalidParameter`. The client currently receives an HTTP OK response containing the error message. The developer wants the API Gateway endpoint to return an HTTP Bad Request status code when this error occurs.
Which configuration steps should the developer take in API Gateway to map this error?
- AConfigure a mapping template in the Integration Request settings to match the string `InvalidParameter` and override the response status code to .
- BEnable Lambda Proxy Integration in the Integration Request, then configure an HTTP status code in the Method Response and map the error message in the Integration Response.
- Define an HTTP response in the Method Response settings. Under the Integration Response settings, create a response with the Lambda Error Regex set to `.*InvalidParameter.*` and associate it with the HTTP Method Response.Answer
- DConfigure a custom Lambda authorizer for the GET method to inspect the backend response and return a policy that generates an HTTP Gateway Response.
Answer
Define an HTTP 400 response in the Method Response settings, and under the Integration Response settings, create a response with the Lambda Error Regex set to match the error string and associate it with the HTTP 400 Method Response.
In a Lambda custom (non-proxy) integration, mapping a backend Lambda error to a specific HTTP status code requires two steps: first, declaring the target HTTP status code (such as ) in the Method Response configuration, and second, setting up an Integration Response with a regular expression (Lambda Error Regex) that matches the error message string returned by Lambda (e.g., `.*InvalidParameter.*`) and linking it to the declared Method Response.
Step-by-Step Solution
Key Concept
Lambda custom (non-proxy) integrations require configuring Method Responses and Integration Responses with Lambda Error Regex to map backend errors to client HTTP status codes.
Estimated Time:1m 30s