A developer is designing a serverless mobile application that integrates with a REST API hosted on Amazon API Gateway. Users must be able to register and sign in directly through the mobile application. The developer needs to secure the API Gateway endpoints so that only authenticated users can access them, while minimizing custom code and operational costs.
Which two actions should the developer take to meet these requirements? (Select TWO.)
- Configure an Amazon Cognito User Pool authorizer in Amazon API Gateway and associate it with the API methods.Answer
- Configure the mobile application to send the Cognito ID token in the Authorization header of the HTTP requests.Answer
- CCreate a custom Lambda authorizer in Amazon API Gateway that decodes and validates the Cognito JSON Web Token (JWT) signature.
- DCreate an Amazon Cognito Identity Pool to exchange the Cognito User Pool token for temporary AWS credentials, and configure IAM authorization on the API methods.
- EApply an API Gateway resource policy that explicitly allows requests where the principal matches the Amazon Cognito User Pool ARN.
Answer
The developer should configure an Amazon Cognito User Pool authorizer in Amazon API Gateway, associate it with the API methods, and configure the mobile application to send the Cognito ID token in the Authorization header of the HTTP requests.
The correct options are configuring a built-in Cognito User Pool authorizer in API Gateway and passing the ID token in the Authorization header. This natively offloads JWT verification to API Gateway without custom code, minimizing cost. The API Gateway Cognito authorizer validates the signature, audience, and expiration of the ID token passed in the Authorization header.
Step-by-Step Solution
Key Concept
Amazon API Gateway integrates natively with Amazon Cognito User Pools using a built-in authorizer. This allows developers to validate JSON Web Tokens (JWTs) generated by Cognito without writing custom Lambda functions. The client application passes the Cognito ID token in the request header, and API Gateway automatically validates it before forwarding the request to downstream services.