A developer is configuring an Amazon API Gateway REST API with a Lambda proxy integration. The backend AWS Lambda function needs to return a custom HTTP status code of 201 (Created), a custom header, and a JSON payload to the client. How must the developer structure the response returned by the Lambda function?
- AConfigure integration response mapping templates in API Gateway to extract the custom header and HTTP status code from the Lambda function's default output properties.
- BUse a custom Lambda authorizer to modify the response headers and HTTP status code before the API Gateway forwards the payload to the client.
- Return a JSON object from the Lambda function containing statusCode, headers, and body fields, with the body field stringified.Answer
- DReturn the raw application JSON payload directly, because API Gateway automatically maps the payload and defaults to a 201 status code for successful Lambda executions.
Answer
Return a JSON object from the Lambda function containing statusCode, headers, and body fields, with the body field stringified.
In a Lambda proxy integration, the backend Lambda function is fully responsible for determining the structure of the HTTP response. To return custom status codes, headers, and payloads, the developer must return a JSON object with the keys 'statusCode', 'headers', and 'body' (where the body payload must be serialized to a string). API Gateway parses this object to construct the final HTTP response sent back to the client.
Step-by-Step Solution
Key Concept
Lambda Proxy Integration Response Format
Estimated Time:1m 0s