Soru

Zorluk: OrtaAPI Development and Integration with Amazon API Gateway

A developer is designing an API in Amazon API Gateway that routes incoming client requests to an AWS Lambda function. To keep the Lambda function's logic simple and decoupled from the API structure, the developer wants the function to receive a specific, simplified JSON payload containing only the client's source IP and a custom API header called 'X-App-Version'. The developer wants to avoid parsing the full HTTP request structure within the Lambda function code. Which API Gateway integration strategy should the developer use to meet these requirements?

  1. Configure a Lambda custom (non-proxy) integration, and use an integration request mapping template in Velocity Template Language (VTL) to extract the source IP and header into the required JSON format.Cevap
  2. B
    Configure a Lambda proxy integration, and access the source IP and header fields directly from the parsed input event object inside the Lambda function.
  3. C
    Configure a custom Lambda authorizer to validate the header, and configure it to inject the source IP into the Lambda execution context.
  4. D
    Configure a Lambda proxy integration, and configure API Gateway CORS response headers mapping to filter out all request fields except the source IP and header.

Cevap

Configure a Lambda custom (non-proxy) integration, and use an integration request mapping template in Velocity Template Language (VTL) to extract the source IP and header into the required JSON format.
A Lambda custom (non-proxy) integration allows the developer to define an integration request mapping template using Velocity Template Language (VTL). This template can extract parameters from the request context (like the source IP) and headers, and construct a custom JSON payload that is sent to the Lambda function. As a result, the Lambda function only receives the mapped parameters and does not need to parse the full HTTP request structure.

Adım Adım Çözüm

1
Identify the requirement to transform the incoming API Gateway request before it reaches the backend Lambda function, specifically avoiding the ingestion and parsing of the entire raw HTTP request wrapper within the Lambda function code.
Limits the solution to API Gateway integration types that support request transformation.
This requirement ensures that the Lambda function remains simple and decoupled from the API request format.
2
Evaluate the integration types in API Gateway. Lambda Proxy integration forwards the raw request wrapper directly to Lambda, shifting the parsing responsibility to the function. Lambda Custom (non-proxy) integration allows the creation of request mapping templates.
Establishes that Lambda Custom (non-proxy) integration is required.
Only custom integration supports payload mapping and transformation before the request reaches the backend integration.
3
Determine the correct technology for payload modification. Velocity Template Language (VTL) in the integration request template is used to extract the source IP (via context.identity.sourceIp)andheaders(viacontext.identity.sourceIp) and headers (via input.params('X-App-Version')) and format them into the desired JSON structure.
Identifies the exact configuration path to build the desired integration payload.
VTL mapping templates are the standard mechanism in API Gateway to map and transform request parameters and body contents for non-proxy integrations.

Anahtar Kavram

API Gateway Integration Types and Request Mapping Templates
Bu soruyu puanla