Question

Difficulty: HardAPI Development and Integration with Amazon API Gateway

A developer is configuring a REST API in Amazon API Gateway that integrates with an AWS Lambda function. The API must use a Lambda non-proxy (custom) integration to allow request transformation. The developer needs to pass the incoming client request header X-App-Tenant-Id as a JSON property named tenantId in the payload sent to Lambda. Additionally, if the Lambda function fails with an error message containing TenantSuspended, the API must return an HTTP 403 Forbidden status code and a custom JSON message to the client. Which two configurations are required to meet these requirements? (Select two.)

  1. Define a mapping template of type application/json in the Integration Request that extracts the header value using the expression $input.params('X-App-Tenant-Id').Answer
  2. Configure an Integration Response with a Lambda Error Regex pattern set to .*TenantSuspended.* and map it to a Method Response with a 403 status code.Answer
  3. C
    Enable Lambda Proxy Integration, then configure the Integration Response regex to intercept the Lambda execution error and map it to a 403 status code.
  4. D
    Create a custom Lambda Authorizer to catch the backend Lambda execution exception and return an IAM policy denying access to the resource.
  5. E
    Configure an API Gateway Response of type DEFAULT_5XX to intercept the Lambda error and map the response body to a 403 status code.

Answer

To pass the header, define an Integration Request mapping template for application/json that extracts the header using $input.params('X-App-Tenant-Id'). To map the backend error, configure an Integration Response with a Lambda Error Regex pattern matching .*TenantSuspended.* and map it to a 403 Method Response.
The correct configurations are defining a mapping template in the Integration Request using the $input.params('X-App-Tenant-Id') expression, and configuring an Integration Response with a Lambda Error Regex pattern to capture the exception and return a 403 Method Response. With Lambda non-proxy integration, developers use Integration Request mapping templates to extract parameters and shape the payload, and Integration Responses to map backend error messages to target HTTP status codes.

Step-by-Step Solution

1
Configure the Integration Request mapping template.
Extracts the client header value and constructs a JSON payload with a tenantId property for the backend Lambda function.
Because Lambda non-proxy integration is used, API Gateway must explicitly transform the incoming HTTP request metadata into a JSON format expected by the Lambda function.
2
Configure a Method Response for the resource method.
Defines an HTTP 403 status code response block for the client.
API Gateway requires that the HTTP status code (Method Response) be defined before the integration response mapping can target it.
3
Configure the Integration Response mapping rules.
Matches the error message string from Lambda using regex and maps the execution result to the 403 Method Response.
For custom integrations, API Gateway evaluates the errorMessage field returned from Lambda against the configured regex pattern to determine which HTTP response code to send back.

Key Concept

API Gateway Lambda Custom Integration Request and Response Mapping
Estimated Time:2m 0s
Rate this question