A developer is designing a serverless backend where a single-page application (SPA) needs to access a private REST API hosted on Amazon API Gateway. The developer wants to authenticate users using an Amazon Cognito User Pool and grant them access to the API Gateway endpoints. The client application needs to acquire a JSON Web Token (JWT) after user login and pass it to API Gateway for validation. Which configuration should the developer implement in API Gateway to authorize these requests with the least administrative effort and cost?
- Create a Cognito User Pool Authorizer in API Gateway, and configure the API method to use this authorizer while specifying the Identity Source header.Answer
- BCreate a custom Lambda authorizer that receives the JWT, validates it using the Cognito public JSON Web Key Set (JWKS), and returns an IAM policy allowing the method execution.
- CCreate an Amazon Cognito Identity Pool, configure API Gateway to use AWS_IAM authorization, and configure the client application to directly pass the Cognito Identity Pool ID in the request header.
- DEnable Lambda Proxy integration for the integration request, and parse the Cognito JWT inside the backend Lambda function to perform authorization checks before processing the business logic.
Answer
Create a Cognito User Pool Authorizer in API Gateway, and configure the API method to use this authorizer while specifying the Identity Source header.
The correct option is to create a Cognito User Pool Authorizer in API Gateway and configure the API method to use this authorizer. This option represents the native integration designed specifically for Amazon Cognito User Pools. It automatically validates incoming JWT signatures, expiration, and audiences at the API Gateway edge, requiring zero custom code and adding no extra execution costs for custom Lambda authorizers.
Step-by-Step Solution
Key Concept
API Gateway Cognito User Pool Authorizer
Estimated Time:1m 30s