A developer is configuring a REST API in Amazon API Gateway that integrates with a backend AWS Lambda function. The developer needs the Lambda function to directly control the HTTP status code and headers returned to the API client. Which two configurations must be implemented to achieve this?
- Enable Lambda Proxy Integration on the API Gateway method integration.Answer
- Ensure the Lambda function returns a JSON response containing the keys 'statusCode', 'headers', and 'body'.Answer
- CConfigure Integration Response mapping templates in the API Gateway console to map the backend response to the HTTP response.
- DDefine the allowed HTTP status codes in the Method Response section in API Gateway.
- EConfigure a custom Lambda Authorizer to rewrite the HTTP headers and status codes before they are sent to the client.
Answer
To allow the Lambda function to control the HTTP status code and response headers, the developer must enable Lambda Proxy Integration on the API Gateway method integration, and the Lambda function must return a JSON response object containing the keys 'statusCode', 'headers', and 'body'.
To allow the Lambda function to control the response status codes and headers, the API Gateway integration must be configured for Lambda Proxy Integration. In this mode, API Gateway forwards the backend response directly to the client. The backend Lambda function must return the response in a standardized JSON payload format containing 'statusCode', 'headers', and 'body' so that API Gateway can correctly build the HTTP response.
Step-by-Step Solution
Key Concept
API Gateway Lambda Proxy Integration response mapping and JSON output schema requirements