A developer is designing a secure REST API using Amazon API Gateway that will be consumed by external client applications. The clients authenticate against a third-party Identity Provider (IdP) that is not compatible with Amazon Cognito, receiving a custom JSON Web Token (JWT) that includes specific scopes in the payload. The REST API must authorize access to resources based on these scopes and forward the verified user identity metadata to a backend Lambda function using a Lambda proxy integration. The developer wants to implement a solution that minimizes both authorization latency and cost. Which configuration should the developer implement to meet these requirements?
- AConfigure the API Gateway integration to use a Lambda custom integration with a request mapping template that forwards the custom JWT. Perform the JWT validation and policy evaluation directly inside the backend Lambda function, caching the validation results in an Amazon ElastiCache cluster to minimize authorization latency on subsequent requests.
- Configure a Lambda authorizer in API Gateway to validate the custom JWT. In the authorizer's response, include the allowed route permissions in the IAM policy document, and map the user identity metadata to the context object. Enable authorization caching by defining an Identity Source, and retrieve the metadata from the requestContext.authorizer object in the backend Lambda function.Cevap
- CConfigure a Cognito User Pool authorizer in API Gateway, and link it to an Amazon Cognito Identity Pool that federates with the third-party Identity Provider. Retrieve the custom scopes and user identity metadata from the requestContext.authorizer.claims object in the backend Lambda function, and configure API Gateway caching on the client's IAM role.
- DConfigure a Cognito User Pool authorizer in API Gateway to validate the custom JWT. Set the authorizer's Identity Source to the Authorization header, and configure a custom Lambda integration mapping template to extract the third-party JWT and exchange it for an IAM policy before executing the backend Lambda function.
Cevap
Configure a Lambda authorizer in API Gateway to validate the custom JWT. In the authorizer's response, include the allowed route permissions in the IAM policy document, and map the user identity metadata to the context object. Enable authorization caching by defining an Identity Source, and retrieve the metadata from the requestContext.authorizer object in the backend Lambda function.
The correct solution uses an API Gateway Lambda authorizer to validate the third-party JWT. Because the token is not issued by Amazon Cognito, a built-in Cognito authorizer cannot be used. By setting an Identity Source (such as the Authorization header), API Gateway caches the generated IAM policy, preventing downstream invocations of the authorizer Lambda function on subsequent calls with the same token. Additionally, return values in the context object from the authorizer are forwarded to the backend Lambda function under requestContext.authorizer, satisfying the requirement to pass user metadata securely while keeping backend processing optimized.
Adım Adım Çözüm
Anahtar Kavram
Using API Gateway Lambda authorizers to validate third-party JSON Web Tokens (JWTs) and caching the authorization policy response to minimize backend invocations.
Tahmini Süre:2m 0s