A developer is building a mobile fitness application that integrates with an Amazon API Gateway REST API backed by AWS Lambda. The application requires users to sign in using their corporate Google Workspace accounts via OpenID Connect (OIDC). Once authenticated, the mobile client must send a secure token with every API request. The API Gateway must validate this token before forwarding the request to the Lambda function. Additionally, the Lambda function needs to access the user's Cognito group memberships to enforce fine-grained access control.
Which solution meets these requirements with the least operational overhead?
- AConfigure an Amazon Cognito Identity Pool with Google as an identity provider. Secure the API Gateway REST API using a custom API Gateway Lambda authorizer that exchanges the Google token for temporary credentials, validates the session, and retrieves the group claims.
- Configure an Amazon Cognito User Pool with Google as an identity provider. Secure the API Gateway REST API using an API Gateway Cognito User Pool authorizer, and configure the API Gateway to use Lambda proxy integration. In the Lambda function, inspect the requestContext.authorizer.claims object to retrieve the user's groups.Answer
- CConfigure an Amazon Cognito User Pool with Google as an identity provider. Implement a custom API Gateway Lambda authorizer that validates the JSON Web Token (JWT) sent by the client, calls the Cognito AdminGetUser API to retrieve user attributes, and passes the claims in the authorization context.
- DConfigure an Amazon Cognito Identity Pool with Google as an identity provider. Set the API Gateway method authorization to AWS_IAM. Have the mobile application exchange the OIDC token for temporary AWS credentials via the Identity Pool, sign requests using Signature Version 4, and pass the group information in a custom request header.
Answer
Configure an Amazon Cognito User Pool with Google as an identity provider, secure the API Gateway using a built-in Cognito User Pool authorizer with Lambda proxy integration, and inspect the requestContext.authorizer.claims object in the Lambda function.
The correct solution utilizes an Amazon Cognito User Pool to manage authentication with the OIDC provider (Google) and secures the API Gateway REST API using the native Cognito User Pool authorizer. This authorizer validates incoming JSON Web Tokens (JWTs) automatically without writing custom code. Using a Lambda proxy integration ensures that all claims, including user groups, are parsed and passed in the requestContext.authorizer.claims object of the Lambda event payload, minimizing operational overhead.
Step-by-Step Solution
Key Concept
Amazon Cognito User Pool Authorizer integration with Amazon API Gateway and Lambda proxy integration.