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 Not Found status code to the client.
How should the developer configure API Gateway to meet these requirements?
- AConfigure an Integration Request mapping template that maps ` context.authorizer.claims.tenantId` into the payload. Define a Method Response, and configure an Integration Response with the Lambda Error Regex set to `.*EntityNotFound.*` mapped to the Method Response.
- Configure an Integration Request mapping template that maps ` context.authorizer.tenantId` into the payload sent to the backend function. Define a Method Response. Create an Integration Response with the Lambda Error Regex set to `.*EntityNotFound.*` and map it to the Method Response.Answer
- CConfigure a Lambda Proxy integration, and access `event.requestContext.identity.sourceIp` and `event.requestContext.authorizer.tenantId` in the backend function. Define a Method Response and configure the Lambda Error Regex in the Integration Response to match `.*EntityNotFound.*`.
- DConfigure an Integration Request mapping template that maps ` 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 .
Answer
Configure an Integration Request mapping template that maps ` context.authorizer.tenantId` into the payload sent to the backend function. Define a Method Response. Create an Integration Response with the Lambda Error Regex set to `.*EntityNotFound.*` and map it to the Method Response.
The correct option correctly identifies the use of an Integration Request mapping template with ` context.authorizer.tenantId` to pass the required dynamic parameters to the backend. It also correctly defines the Method Response and the Integration Response with a regular expression (`.*EntityNotFound.*`) matching the backend exception to map it to the client response code. This represents the standard process for request and response mapping in API Gateway custom integrations.
Step-by-Step Solution
Key Concept
API Gateway Custom Integration Response and Context Mapping