Question

Difficulty: HardAPI Development and Integration with Amazon API Gateway

A developer is transitioning an Amazon API Gateway REST API from a Lambda custom (non-proxy) integration to a Lambda proxy integration. The backend Lambda function needs to access the client's IP address and a query string parameter named `version` that were previously mapped via a Velocity Template Language (VTL) mapping template. The Lambda function also must return a custom HTTP status code of `201 Created` along with a JSON payload.

Which TWO actions must the developer take to accomplish this transition successfully? (Select TWO.)

  1. Access the client's IP address from `event.requestContext.identity.sourceIp` and the query string parameter from `event.queryStringParameters.version` in the Lambda input event.Answer
  2. Update the Lambda function's return object to include a `statusCode` key with a value of `201` and a stringified JSON payload in the `body` key.Answer
  3. C
    Configure an Integration Request mapping template in API Gateway to extract the IP address via `$context.identity.sourceIp` and pass it to the Lambda function.
  4. D
    Configure an Integration Response mapping template in API Gateway to map the custom JSON response keys to the HTTP `201` status code.
  5. E
    Deploy a Lambda Authorizer to validate the query string parameters and return the client's IP address inside the authorization context.

Answer

Access the client's IP address from the request context and the query string parameter from the query string parameters block in the Lambda input event, and update the Lambda function's return object to include a statusCode of 201 and a stringified JSON payload in the body.
In a Lambda proxy integration, Amazon API Gateway automatically maps the client request into a standard JSON event structure and passes it directly to the Lambda function. The developer can access the client's IP address from `event.requestContext.identity.sourceIp` and the query string parameter from `event.queryStringParameters.version`. Furthermore, the Lambda function is responsible for returning a response formatted according to the proxy integration contract, which requires an object containing a `statusCode` (such as `201`) and a stringified JSON payload in the `body` field.

Step-by-Step Solution

1
Analyze the change in request format from Custom to Proxy integration.
Identify that the Lambda input event is now a standardized proxy event payload instead of a custom JSON object created by a VTL template.
This determines where to look for the client's IP address and query string parameters.
2
Locate the client IP and query parameters in the proxy input event structure.
Find the client IP at `event.requestContext.identity.sourceIp` and the `version` parameter at `event.queryStringParameters.version`.
These locations are predefined in the AWS Lambda proxy integration event format.
3
Analyze the change in response format for Lambda proxy integration.
Identify that API Gateway bypasses Integration Response configurations and expects the Lambda function to return a structured JSON response.
This determines how the custom HTTP status code and response payload must be structured.
4
Structure the Lambda return object to match proxy integration requirements.
Return a JSON object containing the `statusCode` as `201` and the response payload as a stringified JSON string in the `body` field.
API Gateway will fail with a 502 Bad Gateway error if the response format does not match this structure.

Key Concept

Understanding the input and output payload contract for AWS Lambda Proxy integrations versus Custom integrations in Amazon API Gateway.
Rate this question