A developer is building a serverless REST API using Amazon API Gateway and AWS Lambda. The API must authenticate users who are managed in an external identity provider that supports OpenID Connect (OIDC). The requirements specify that the solution must minimize custom code, validate the JSON Web Token (JWT) at the API Gateway layer, and securely pass user attributes—such as custom groups—to the backend Lambda function for fine-grained authorization. Additionally, the client application must not need to manage or sign requests with temporary AWS credentials.
Which architecture should the developer implement to meet these requirements with the least administrative effort?
- Configure an Amazon Cognito User Pool federated with the external OIDC provider. Set up an API Gateway Cognito Authorizer that points to the Cognito User Pool. In the API Gateway Method Request, set the Authorization header. In the backend Lambda function, extract the user attributes from the request's context event under the authorizer claims.Answer
- BConfigure an Amazon Cognito Identity Pool federated with the external OIDC provider. Set up an API Gateway IAM Authorizer. Have the client application exchange the OIDC token for temporary AWS credentials using the Identity Pool, sign each HTTP request using Signature Version 4, and pass user attributes in custom headers.
- CCreate a custom Lambda authorizer that performs manual token signature validation using a public key endpoint from the external OIDC provider. In the Lambda authorizer, parse the custom groups and return them inside the context object of the authorization response. Access these claims inside the backend Lambda function using a custom integration mapping template.
- DConfigure an Amazon Cognito User Pool federated with the external OIDC provider. Configure a custom Lambda authorizer to intercept the token and write a Lambda Proxy Integration mapping template to parse the JWT payload. Inside the backend Lambda function, map the raw request payload back to the Cognito User Pool to retrieve user attributes.
Answer
Configure an Amazon Cognito User Pool federated with the external OIDC provider, set up an API Gateway Cognito Authorizer pointing to the user pool, and extract the user attributes from the request's context event under the authorizer claims in the backend Lambda function.
The correct solution uses an Amazon Cognito User Pool federated with the external OIDC provider. This configuration allows API Gateway to leverage the built-in Cognito Authorizer, which handles token validation at the gateway edge. Verified claims are automatically passed to the Lambda function in the request context event, eliminating custom validation code and client-side request signing.
Step-by-Step Solution
Key Concept
API Gateway Cognito User Pool Authorizer integration for federated OIDC authentication.