A developer is designing a REST API using Amazon API Gateway. The API must restrict access to authenticated users who log in using an Amazon Cognito user pool. The developer wants to validate the JSON Web Tokens (JWTs) sent in the request authorization header with the minimum amount of custom code and maintenance overhead. Which of the following is the most appropriate method to authorize these requests?
- ACreate a custom Lambda authorizer that decodes and verifies the signatures of the Cognito tokens using an external library.
- Configure a built-in Amazon Cognito user pool authorizer in API Gateway to validate the incoming tokens.Answer
- CConfigure an Amazon Cognito identity pool authorizer in API Gateway to validate the user pool tokens.
- DEnable API Gateway Lambda proxy integration and write custom token verification logic in the backend Lambda function.
Answer
Configure a built-in Amazon Cognito user pool authorizer in API Gateway to validate the incoming tokens.
Configuring a built-in Amazon Cognito user pool authorizer allows API Gateway to natively decode and validate JSON Web Tokens (JWTs) provided by Cognito User Pools. This approach is highly efficient, requires no custom code, and rejects unauthorized requests before invoking any backend integrations.
Step-by-Step Solution
Key Concept
API Gateway built-in Cognito User Pool Authorizers