A software team is transitioning an Amazon API Gateway REST API endpoint from a Lambda custom integration to a Lambda proxy integration to reduce configuration overhead. Currently, the backend AWS Lambda function receives a pre-mapped JSON payload containing only application data, and it returns a custom business object directly. What modification must be made to the Lambda function code to ensure the API endpoint continues to function correctly under the new integration?
- Modify the code to extract request details from the raw event object (such as event.body) and format the returned value as a JSON object containing statusCode, headers, and a stringified body.Cevap
- BKeep the existing business object return format but update the function's input parameter to accept a serialized JSON string representing the entire HTTP request.
- CConfigure the function to return a standard HTTP response stream using the AWS SDK, and parse the query parameters from the system environment variables.
- DIntegrate a custom Lambda authorizer inside the existing handler code to parse client request headers and automatically map them to the client integration response.
Cevap
Modify the code to extract request details from the raw event object (such as event.body) and format the returned value as a JSON object containing statusCode, headers, and a stringified body.
Under Lambda proxy integration, Amazon API Gateway passes the raw HTTP request to the Lambda function in the event object. The Lambda function is responsible for parsing the input (such as event.body) and must return the response in a structured format containing statusCode, headers, and body as a string. This eliminates the need to configure integration request and response mappings in API Gateway.
Adım Adım Çözüm
Anahtar Kavram
Lambda Proxy vs Custom Integration request/response handling