A developer is building a serverless backend for a web application using Amazon API Gateway and AWS Lambda. The API must secure its endpoints by authenticating users against an Amazon Cognito User Pool. The backend Lambda function needs access to the user's Cognito group memberships (claims) as well as the request's HTTP headers and query string parameters. To reduce development time and minimize latency, the developer wants to avoid writing custom authorization code or custom payload mapping logic. Which configuration should the developer implement?
- AConfigure a custom Lambda Authorizer in API Gateway to validate the Cognito JWT token, and configure the integration type as Lambda Proxy Integration.
- BConfigure the API method with no API Gateway authorizer, use Lambda Proxy Integration, and perform the Cognito JWT token validation and claims extraction within the backend Lambda function code.
- Configure a Cognito User Pool Authorizer in API Gateway for the REST API method, and configure the integration type as Lambda Proxy Integration.Cevap
- DConfigure a Cognito User Pool Authorizer in API Gateway, and configure the integration type as Lambda Custom Integration with a custom Velocity Mapping Template.
Cevap
Configure a Cognito User Pool Authorizer in API Gateway for the REST API method, and configure the integration type as Lambda Proxy Integration.
The correct configuration utilizes a Cognito User Pool Authorizer combined with Lambda Proxy Integration. The Cognito User Pool Authorizer natively handles JWT validation without requiring custom code, and automatically exposes claims in the request context. The Lambda Proxy Integration automatically passes all request components, including query strings, headers, and the authorizer claims, to the backend Lambda function in a structured format.
Adım Adım Çözüm
Anahtar Kavram
API Gateway Integration with AWS Lambda and Amazon Cognito