A developer is implementing a secure authentication and authorization mechanism for a web-based client portal. The portal consists of a React single-page application (SPA) and an Amazon API Gateway REST API backed by AWS Lambda. The developer must allow users to sign in, retrieve their profile details, and enforce group-based access control (e.g., Administrators vs. Standard Users) on the API Gateway endpoints. The architecture must minimize latency, avoid unnecessary external API calls during request processing, and leverage built-in AWS integrations where possible.
Which TWO actions should the developer take to meet these requirements?
- Configure a Cognito User Pool to manage user identities, and associate a Cognito User Pools authorizer with the API Gateway REST API.Answer
- Configure the API Gateway integration to forward token claims, and inspect the cognito:groups claim within the Lambda request context to determine user permissions.Answer
- CCreate a Cognito Identity Pool to obtain temporary AWS credentials for authenticated users, and configure API Gateway to use AWS_IAM authorization with a custom Lambda authorizer to validate the signature.
- DConfigure a custom Lambda authorizer on API Gateway to perform manual token signature validation, and call the AdminListGroupsForUser API inside the Lambda authorizer to fetch user groups.
- EDefine an IAM role trust policy that allows the API Gateway execution role to assume Cognito Identity Pool roles, and map user groups to IAM policies directly through the API Gateway execution role.
Answer
To implement the authentication and authorization flow, configure a Cognito User Pool with a Cognito User Pools authorizer on the API Gateway REST API. Then, check user groups in the backend Lambda function by inspecting the cognito:groups claim inside the request context.
The correct approach is to use a Cognito User Pool combined with a Cognito User Pools authorizer on API Gateway, and to inspect the cognito:groups claim inside the backend Lambda function. The Cognito User Pool serves as the user directory and generates JWT tokens. API Gateway's built-in Cognito authorizer natively validates these tokens, reducing latency. After validation, API Gateway forwards the token claims (including the user's groups in the cognito:groups claim) directly to the Lambda request context, enabling authorization checks without any additional Cognito API calls.
Step-by-Step Solution
Key Concept
Using Cognito User Pools with native API Gateway authorizers to authenticate users and forwarding claims to AWS Lambda for group-based authorization.
Estimated Time:2m 0s