A software engineer is configuring security for a web application where clients send requests to a REST API hosted on Amazon API Gateway. The application uses an Amazon Cognito User Pool for user authentication. The engineer must restrict access to the REST API so that only authenticated users with a valid JSON Web Token (JWT) can call the endpoints, without writing custom code to decode or validate the tokens. Which solution meets these requirements with the least operational overhead?
- Configure an Amazon Cognito authorizer on the API Gateway REST API, referencing the User Pool, and pass the identity token in the request header.Cevap
- BConfigure a custom Lambda authorizer on the API Gateway REST API. In the Lambda function, fetch the JSON Web Key Set (JWKS), decode the token, and validate the token signature.
- CConfigure an Amazon Cognito Identity Pool as the authorizer for the API Gateway REST API to automatically validate the user's JSON Web Token (JWT) token.
- DCreate an IAM trust policy that allows API Gateway to assume an IAM role associated with the Amazon Cognito User Pool to validate each request.
Cevap
Configure an Amazon Cognito authorizer on the API Gateway REST API, referencing the User Pool, and pass the identity token in the request header.
The correct solution uses an API Gateway Cognito authorizer linked to the Amazon Cognito User Pool. This is a built-in feature that automatically validates incoming JWT tokens (such as the ID token) without requiring any custom Lambda code, meeting all constraints with the lowest operational overhead.
Adım Adım Çözüm
Anahtar Kavram
API Gateway integration with Amazon Cognito User Pools using Cognito Authorizers
Tahmini Süre:1m 30s