Q71 — AWS DVA-C02 Ch.2
Question 71 of 100 | ← Chapter 2
A developer is debugging an AWS Lambda function behind Amazon API Gateway. Every time the API Gateway endpoint is invoked, it returns an HTTP status code of 200, even though the AWS Lambda function is logging 4xx errors. What changes must be made to enable API Gateway to return the correct error codes?
- A. Enable CORS in the API Gateway method settings.
- B. Use Lambda proxy integration to return HTTP status codes and headers. ✓
- C. Enable API Gateway error passthrough.
- D. Return the value in the x-amzn-ErrorType header.
Correct Answer: B. Use Lambda proxy integration to return HTTP status codes and headers.
Explanation
With Lambda proxy integration, the Lambda function must return a response in a specific format that includes a 'statusCode' field—typically 4XX (client errors) or 5XX (server errors). API Gateway uses this statusCode to map Lambda errors to appropriate HTTP error responses. To pass through error types (e.g., InvalidParameterException) to the client, the Lambda function must include the 'X-amzn-ErrorType' header (e.g., 'InvalidParameterException') in its response.