Question

Difficulty: MediumAPI Development and Integration with Amazon API Gateway

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?

  1. 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.Answer
  2. B
    Keep the existing business object return format but update the function's input parameter to accept a serialized JSON string representing the entire HTTP request.
  3. C
    Configure the function to return a standard HTTP response stream using the AWS SDK, and parse the query parameters from the system environment variables.
  4. D
    Integrate a custom Lambda authorizer inside the existing handler code to parse client request headers and automatically map them to the client integration response.

Answer

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.

Step-by-Step Solution

1
Analyze the change in input payload format.
In a Lambda proxy integration, API Gateway does not apply mapping templates. The input payload becomes the raw HTTP request details encapsulated in the event object, meaning the handler must access fields like event.body or event.queryStringParameters directly.
To correctly process client data that was previously mapped.
2
Analyze the change in output payload format.
In a Lambda proxy integration, API Gateway bypasses integration response mapping templates. The Lambda function must return a JSON response conforming to a specific format: containing statusCode, headers, and body (as a string).
To prevent API Gateway from returning a 502 Bad Gateway error to the client due to a malformed proxy response.

Key Concept

Lambda Proxy vs Custom Integration request/response handling
Rate this question