Soru

Zorluk: OrtaAPI Development and Integration with Amazon API Gateway

A developer is building a REST API using Amazon API Gateway that integrates with an existing AWS Lambda function. The Lambda function expects a JSON payload containing specific keys: `searchCategory` and `maxResults`. However, client applications will send requests containing query string parameters `category` and `limit` (for example, `/items?category=books&limit=10`). The developer wants API Gateway to transform these incoming query string parameters into the required JSON payload structure before invoking the Lambda function.

Which integration approach should the developer implement to meet these requirements?

  1. A
    Configure a Lambda proxy integration and define a request mapping template to transform the query string parameters before passing them to the Lambda function.
  2. Configure a Lambda custom integration and define a request mapping template in API Gateway to map the query string parameters to the required JSON format.Cevap
  3. C
    Configure a Lambda proxy integration and configure stage variables to rewrite the query parameters into the Lambda event object.
  4. D
    Configure a Lambda authorizer to intercept the request, transform the query parameters, and inject the mapped JSON payload into the request context.

Cevap

Configure a Lambda custom integration and define a request mapping template in API Gateway to map the query string parameters to the required JSON format.
Configuring a Lambda custom integration (non-proxy integration) allows the developer to define an Integration Request mapping template. This template uses Velocity Template Language (VTL) to transform the incoming HTTP request query string parameters into the structured JSON payload format expected by the Lambda function before invocation.

Adım Adım Çözüm

1
Determine the correct integration type for request transformation.
Select Lambda custom (non-proxy) integration.
Proxy integrations pass the raw request format directly to the backend without modification, whereas custom integrations allow mapping templates to transform client requests.
2
Configure the Integration Request mapping template.
Create a template for application/json mapping the query parameters to the expected JSON keys.
API Gateway uses Velocity Template Language (VTL) mapping templates to extract the query string values and format them into the structured JSON payload required by the backend Lambda function.

Anahtar Kavram

API Gateway Lambda Custom vs. Proxy Integration
Bu soruyu puanla