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?
- 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
- BConfigure a Lambda proxy integration, and access the source IP and header fields directly from the parsed input event object inside the Lambda function.
- CConfigure a custom Lambda authorizer to validate the header, and configure it to inject the source IP into the Lambda execution context.
- DConfigure 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
Anahtar Kavram
API Gateway Integration Types and Request Mapping Templates