A developer is building a serverless web application that utilizes Amazon Cognito User Pools for user authentication and Amazon API Gateway REST APIs for backend services. The developer needs to secure the API Gateway endpoints so that only authenticated users can access them. The solution must validate the JSON Web Tokens (JWTs) provided by the client with the least amount of custom code and lowest operational overhead. Which solution should the developer implement to meet these requirements?
- AConfigure an Amazon Cognito Identity Pool to exchange the User Pool token for temporary AWS credentials, and secure the API Gateway REST API using IAM authorization.
- BCreate a custom API Gateway Lambda Authorizer that fetches the JSON Web Key Set (JWKS), validates the incoming token signature, and returns an IAM policy.
- Configure an API Gateway Cognito User Pool Authorizer to directly validate the identity token passed in the request header.Answer
- DSet up an API Gateway Lambda Authorizer that checks the user's group membership by making a synchronous DescribeUser API call to the User Pool on every request.
Answer
Configure an API Gateway Cognito User Pool Authorizer to directly validate the identity token passed in the request header.
Configuring an API Gateway Cognito User Pool Authorizer is the most efficient approach because it is a built-in feature of API Gateway. It automatically validates the identity token passed in the request header against the configured Cognito User Pool client, requiring no custom Lambda function or custom code validation.
Step-by-Step Solution
Key Concept
Amazon API Gateway Cognito User Pool Authorizers