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?
- 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
- BModify the backend Lambda function to retrieve the tenant identifier from the `event.requestContext.authorizer.tenantId` path of the incoming handler event.
- CSwitch the API Gateway authorizer to a Cognito User Pool authorizer, which automatically maps and forwards all custom claims to custom integration backends.
- DConfigure 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
Anahtar Kavram
Custom Integration Mapping Templates and Authorizer Context