Soru

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

A developer is configuring a REST API in Amazon API Gateway using a Lambda custom (non-proxy) integration. The API is secured by a custom Lambda authorizer that outputs a context variable named `tenantId`. The backend Lambda function needs to receive both the client's source IP address and the `tenantId` in its input payload. Furthermore, when the backend Lambda function throws an exception containing the string `EntityNotFound`, the API must return a 404404 Not Found status code to the client.

How should the developer configure API Gateway to meet these requirements?

  1. A
    Configure an Integration Request mapping template that maps `context.identity.sourceIpandcontext.identity.sourceIp` and ` context.authorizer.claims.tenantId` into the payload. Define a 404404 Method Response, and configure an Integration Response with the Lambda Error Regex set to `.*EntityNotFound.*` mapped to the 404404 Method Response.
  2. Configure an Integration Request mapping template that maps `context.identity.sourceIpandcontext.identity.sourceIp` and ` context.authorizer.tenantId` into the payload sent to the backend function. Define a 404404 Method Response. Create an Integration Response with the Lambda Error Regex set to `.*EntityNotFound.*` and map it to the 404404 Method Response.Cevap
  3. C
    Configure a Lambda Proxy integration, and access `event.requestContext.identity.sourceIp` and `event.requestContext.authorizer.tenantId` in the backend function. Define a 404404 Method Response and configure the Lambda Error Regex in the Integration Response to match `.*EntityNotFound.*`.
  4. D
    Configure an Integration Request mapping template that maps `stageVariables.sourceIpandstageVariables.sourceIp` and ` context.authorizer.tenantId` into the payload. Define a custom Gateway Response of type `DEFAULT_5XX` with a mapping template to intercept the `EntityNotFound` error string and rewrite the status code to 404404.

Cevap

Configure an Integration Request mapping template that maps `context.identity.sourceIpandcontext.identity.sourceIp` and ` context.authorizer.tenantId` into the payload sent to the backend function. Define a 404404 Method Response. Create an Integration Response with the Lambda Error Regex set to `.*EntityNotFound.*` and map it to the 404404 Method Response.
The correct option correctly identifies the use of an Integration Request mapping template with `context.identity.sourceIpandcontext.identity.sourceIp` and ` context.authorizer.tenantId` to pass the required dynamic parameters to the backend. It also correctly defines the 404404 Method Response and the Integration Response with a regular expression (`.*EntityNotFound.*`) matching the backend exception to map it to the 404404 client response code. This represents the standard process for request and response mapping in API Gateway custom integrations.

Adım Adım Çözüm

1
Determine the correct integration type and request mapping variables.
Since the scenario specifies custom (non-proxy) integration, mapping templates are required. Identify `context.identity.sourceIpfortheclientIPandcontext.identity.sourceIp` for the client IP and ` context.authorizer.tenantId` for the Lambda authorizer's context output.
Custom integrations do not pass the request context automatically, so the developer must explicitly map these context properties using VTL variables in the Integration Request mapping template.
2
Define the client-facing HTTP status code.
Create a Method Response for the HTTP status code 404404.
Before an Integration Response can map a backend result to a client status code, that status code must first be declared as an available Method Response for the resource method.
3
Configure the error selection pattern to map the Lambda exception.
Create an Integration Response with a selection pattern (Lambda Error Regex) of `.*EntityNotFound.*` and map it to the 404404 Method Response.
When a custom Lambda integration throws an error, the error message returned is matched against the Lambda Error Regex. The regular expression matches the exception type or message to trigger the custom integration response and pass the 404404 status code to the client.

Anahtar Kavram

API Gateway Custom Integration Response and Context Mapping
Bu soruyu puanla