A developer is migrating a backend REST API from a Lambda Custom Integration to a Lambda Proxy Integration in Amazon API Gateway. The client application is an iOS mobile app that sends a POST request to create user profiles. Previously, when the Lambda function encountered a validation error (such as a missing email address), it would throw an exception, and the developer mapped this exception to a 400 Bad Request HTTP status code using API Gateway Integration Responses. After switching the API method to use the Lambda Proxy Integration, the client application receives a 502 Bad Gateway error instead of the 400 Bad Request validation error, even though the Lambda function execution succeeds with the expected validation error logged. Which of the following modifications should the developer make to the Lambda function's code to resolve this issue and return the expected 400 Bad Request status code?
- AConfigure an Integration Response in the API Gateway method execution console with a regular expression mapping to capture the thrown exception and map it to a 400 HTTP status code.
- Modify the Lambda function to catch the validation error and return a JSON object containing a statusCode key set to 400 and a body key containing a serialized JSON string of the error details.Answer
- CAdd an Access-Control-Allow-Origin header to the API Gateway OPTIONS method configuration and configure the static web host's S3 bucket policy to allow external CORS requests.
- DImplement a custom Lambda Authorizer to validate the request payload and return an IAM policy with a context block containing the statusCode mapping of 400.