A developer is designing a REST API in Amazon API Gateway that must secure access to its endpoints using an existing Amazon Cognito User Pool. The developer wants to validate the JSON Web Tokens (JWTs) passed in the `Authorization` header of client requests with the minimum amount of custom code and lowest latency. Which configuration should the developer implement in API Gateway?
- Configure a Cognito User Pool authorizer on the API Gateway methods and set the Token Source to 'Authorization'Answer
- BCreate a custom Lambda token authorizer that performs cryptographic validation of the Cognito JWT and returns an IAM policy
- CImplement a Lambda proxy integration and write application logic in the backend function to inspect the proxy event headers for token verification
- DConfigure an IAM authorizer on API Gateway and write a custom Lambda authorizer to map User Pool tokens to IAM policies
Answer
Configure a Cognito User Pool authorizer on the API Gateway methods and set the Token Source to 'Authorization'
The native Cognito User Pool authorizer in Amazon API Gateway validates the JWT signatures from Cognito User Pools directly at the gateway layer. This requires no custom code, is easy to set up, and avoids the cold-start latency and execution costs of a Lambda function.
Step-by-Step Solution
Key Concept
API Gateway Cognito User Pool Authorizer