A developer is implementing a mobile e-commerce application. The application requires a secure user sign-up and sign-in system. Once authenticated, the application must make secure REST API requests to an Amazon API Gateway backend to fetch order history. The developer wants to use a managed user directory and ensure that API Gateway automatically validates the JSON Web Tokens (JWT) sent in the request header without maintaining custom authentication code or custom backend validation logic.
Which setup meets these requirements with the lowest operational complexity?
- Use an Amazon Cognito User Pool to handle user registration and sign-in. Configure a Cognito User Pool Authorizer on the API Gateway REST API method to validate the ID or access token sent by the mobile application.Answer
- BUse an Amazon Cognito Identity Pool to handle user registration and sign-in. Configure a Cognito Authorizer on the API Gateway REST API method to validate the identity pool tokens directly.
- CUse an Amazon Cognito User Pool to handle user registration and sign-in. Create a custom API Gateway Lambda authorizer that retrieves the public JSON Web Key Set (JWKS) from Cognito to verify the signature and validity of the incoming JWT for each request.
- DStore the user accounts in a backend database. Hardcode an IAM user's AWS access key and secret key within the mobile application's source code, using the AWS SDK to sign each HTTP request before sending it to the API Gateway.
Answer
Use an Amazon Cognito User Pool to handle user registration and sign-in. Configure a Cognito User Pool Authorizer on the API Gateway REST API method to validate the ID or access token sent by the mobile application.
The correct option is to use an Amazon Cognito User Pool to manage sign-in and sign-up, and configure a Cognito User Pool Authorizer on API Gateway. Cognito User Pools natively handle the user directory and issue JWTs (ID/access tokens) upon authentication. API Gateway's built-in Cognito Authorizer directly validates these JWTs without requiring custom Lambda code, which reduces development effort and operational overhead.
Step-by-Step Solution
Key Concept
Amazon Cognito User Pools provide authentication and token issuance, which can be natively validated at API Gateway using a built-in Cognito User Pool Authorizer to secure API endpoints with minimal operational overhead.