Soru

Zorluk: ZorAPI Development and Integration with Amazon API Gateway

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?

  1. A
    Configure a custom Lambda Authorizer in API Gateway to validate the Cognito JWT token, and configure the integration type as Lambda Proxy Integration.
  2. B
    Configure 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.
  3. Configure a Cognito User Pool Authorizer in API Gateway for the REST API method, and configure the integration type as Lambda Proxy Integration.Cevap
  4. D
    Configure 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

1
Create and configure a Cognito User Pool Authorizer in API Gateway pointing to the application's User Pool, and apply it to the REST API method.
API Gateway handles the JWT validation natively, securing the endpoint and extracting user claims into the context without custom authorization code.
To validate incoming authorization tokens at the gateway level with minimal latency and zero compute execution costs.
2
Set the API Gateway integration type to Lambda Proxy Integration.
API Gateway packages all incoming HTTP headers, query string parameters, body, and context parameters (including the Cognito claims under requestContext.authorizer.claims) into a single, standardized JSON event structure.
To avoid writing custom mapping templates and allow the backend Lambda function to receive all request details dynamically.
3
Access the required claims and request metadata from the event object inside the backend Lambda function code.
The Lambda function code can directly parse group memberships from the event object without manual data mapping or token decoding.
To retrieve user context and request parameters efficiently using native integration features.

Anahtar Kavram

API Gateway Integration with AWS Lambda and Amazon Cognito
Bu soruyu puanla