Soru

Zorluk: Çok zorAPI Development and Integration with Amazon API Gateway

A developer is designing a high-throughput REST API using Amazon API Gateway. The API must integrate directly with an external HTTP backend via an HTTP integration. The incoming client request is a POST request with a JSON payload containing a tenantId field in the root of the document. The external HTTP backend requires the tenantId to be passed as a path parameter in the request URL (for example, /tenants/{tenantId}/events). To minimize latency and operational costs, the developer must implement this transformation without using an intermediate AWS Lambda function. Which configuration should the developer use to dynamically map the tenantId from the JSON request body to the HTTP integration request path?

  1. A
    Map the path parameter in the Integration Request settings directly to the Method Request body parameter using the mapping expression method.request.body.tenantId.
  2. Create an API Gateway request mapping template for the integration. Extract the value using input.path(input.path('.tenantId') and override the integration path parameter by setting #set(context.requestOverride.path.tenantId=context.requestOverride.path.tenantId = input.path('$.tenantId')).Cevap
  3. C
    Reference the JSON body parameter directly in the Integration Endpoint URL by using the dynamic path template https://backend.example.com/tenants/{input.path(input.path('.tenantId')}/events.
  4. D
    Configure a custom Lambda authorizer to parse the incoming request body, extract the tenant ID, and return it in the authorizer context to be mapped in the Integration Request parameter settings.

Cevap

Create an API Gateway request mapping template for the integration, extract the value using the VTL path helper, and override the path parameter via the request override context context variable.
The correct approach is to create a request mapping template that extracts the value using input.path(input.path('.tenantId') and overrides the path parameter via context.requestOverride.path.tenantId.AmazonAPIGatewaysupportsmappingoverridesthroughthecontext.requestOverride.path.tenantId. Amazon API Gateway supports mapping overrides through the context.requestOverride context variable in VTL mapping templates. This feature allows developers to dynamically change request paths, query strings, and headers based on the request payload without relying on Lambda functions, maintaining low latency and lower cost.

Adım Adım Çözüm

1
Define an API Gateway request mapping template (e.g., for application/json) in the Integration Request settings.
Allows VTL logic to run during the request phase before forwarding to the backend.
Mapping templates are required to inspect, parse, or manipulate the incoming request payload.
2
Extract the value of the tenantId property from the JSON request payload.
Use input.path(input.path('.tenantId') within the VTL mapping template to capture the client-supplied tenant identifier.
The $input.path() utility function is the standard method for parsing JSON bodies in API Gateway mapping templates.
3
Override the path parameter dynamically using $context.requestOverride.
Apply #set(context.requestOverride.path.tenantId=context.requestOverride.path.tenantId = input.path('$.tenantId')) inside the template.
The $context.requestOverride object allows developers to dynamically modify or inject integration request parameters (headers, query parameters, or paths) directly from within mapping templates, removing the need for a helper Lambda function.

Anahtar Kavram

API Gateway Integration Request Parameter Overrides via VTL
Tahmini Süre:3m 0s
Bu soruyu puanla