A developer is implementing a secure corporate portal that exposes sensitive administrative endpoints through an Amazon API Gateway REST API. The portal's frontend application authenticates users against an Amazon Cognito User Pool. The developer wants to restrict access to these REST API endpoints to authenticated users only. To comply with security best practices and keep development and operational overhead to a minimum, the developer wants to avoid writing and maintaining custom code for token verification. Which approach should the developer use to authorize these API requests?
- AEnable Lambda Proxy integration for the backend Lambda function, extract the authorization header inside the function code, and manually verify the token using the Amazon Cognito SDK.
- BCreate a custom Lambda authorizer that retrieves the JSON Web Key Set (JWKS) from the Amazon Cognito User Pool to manually validate the signature of the incoming bearer token.
- Configure an Amazon Cognito User Pool authorizer on the API Gateway resources, and verify the authorization by passing the identity JSON Web Token (JWT) in the request headers.Answer
- DConfigure an Amazon Cognito Identity Pool to authenticate users directly, and use temporary AWS credentials in the request headers to authenticate against an API Gateway Cognito Authorizer.
Answer
Configure an Amazon Cognito User Pool authorizer on the API Gateway resources, and verify the authorization by passing the identity JSON Web Token (JWT) in the request headers.
Configuring an Amazon Cognito User Pool authorizer is a native, built-in feature of Amazon API Gateway. It validates JSON Web Tokens (JWT) sent in the request header directly against the configured Cognito User Pool without executing custom Lambda code. This approach eliminates custom code development, reduces operational overhead, and minimizes execution costs.
Step-by-Step Solution
Key Concept
Natively securing Amazon API Gateway REST APIs using Cognito User Pool Authorizers to validate JSON Web Tokens (JWT) without custom code execution.