Soru

Zorluk: ZorAPI Development and Integration with Amazon API Gateway

A developer is building a serverless application using an Amazon API Gateway REST API with a Lambda custom (non-proxy) integration backend. The developer configures a custom Lambda authorizer to authenticate incoming requests. The authorizer successfully validates the bearer token and returns an IAM policy along with a context map containing key-value pairs, including a custom property named `tenantId`. However, the backend Lambda function receives `null` for the `tenantId` parameter during invocation.

Which configuration change must the developer implement to resolve this issue?

  1. Define an API Gateway integration request mapping template that references the `$context.authorizer.tenantId` variable to build the JSON payload sent to the Lambda function.Cevap
  2. B
    Modify the backend Lambda function to retrieve the tenant identifier from the `event.requestContext.authorizer.tenantId` path of the incoming handler event.
  3. C
    Switch the API Gateway authorizer to a Cognito User Pool authorizer, which automatically maps and forwards all custom claims to custom integration backends.
  4. D
    Configure a method response header for `Access-Control-Allow-Headers` that includes the authorizer context key, enabling client headers to bypass integration mapping.

Cevap

Define an API Gateway integration request mapping template that references the `$context.authorizer.tenantId` variable to build the JSON payload sent to the Lambda function.
Defining an API Gateway integration request mapping template is the correct resolution. In a Lambda custom (non-proxy) integration, API Gateway does not forward the raw request event or context metadata. The developer must define a mapping template to build the payload sent to the backend, mapping the authorizer context variable using `$context.authorizer.tenantId`.

Adım Adım Çözüm

1
Identify the API Gateway integration type being used.
The API uses a Lambda custom (non-proxy) integration, which means API Gateway does not automatically forward the request payload or context metadata to the backend.
Understanding the difference between proxy and custom integrations is crucial for determining how data is passed to the backend.
2
Determine how custom authorizer context is exposed in API Gateway.
The Lambda authorizer's context map properties are available via the `$context.authorizer.keyName` variables in API Gateway mapping templates.
This allows referencing the specific `tenantId` property returned by the custom authorizer.
3
Configure the Integration Request mapping template.
Create a mapping template for the request content-type (e.g., `application/json`) that constructs a JSON payload containing the mapped context variable, which is then sent to the backend Lambda function.
This ensures the Lambda function receives the expected parameters in its event payload.

Anahtar Kavram

Custom Integration Mapping Templates and Authorizer Context
Bu soruyu puanla