A developer is building a serverless web application. The frontend is a Single-Page Application (SPA). Users must sign in to the application, and the application must perform two main functions:
1. Call a secure REST API hosted on Amazon API Gateway.
2. Download user-specific reports directly from a private Amazon S3 bucket.
Which combination of Amazon Cognito features and configurations should the developer use to meet these requirements? (Select TWO.)
- Configure an Amazon Cognito User Pool to manage user registration and authentication, and implement an Amazon Cognito User Pool authorizer on the API Gateway REST API.Answer
- Configure an Amazon Cognito Identity Pool linked to the User Pool, and associate an IAM role that grants read-only permissions to the Amazon S3 bucket.Answer
- CConfigure an Amazon Cognito Identity Pool to manage the user directory and issue JSON Web Tokens (JWTs) to authenticate requests at API Gateway.
- DConfigure a custom API Gateway Lambda Authorizer to assume an IAM role for S3 access and return the temporary AWS credentials to the client in the API response.
- EConfigure the IAM trust policy of the S3 access role to trust the Cognito User Pool (cognito-idp.amazonaws.com) directly.
Answer
To secure the API Gateway REST API, the developer should configure an Amazon Cognito User Pool to manage user authentication and use a User Pool authorizer on API Gateway. To allow the client to download files directly from S3, the developer should configure an Amazon Cognito Identity Pool linked to the User Pool and associate it with an IAM role that grants S3 read access.
The correct solution involves configuring an Amazon Cognito User Pool to handle user directory, registration, and sign-in. An API Gateway Cognito User Pool Authorizer can then easily validate the ID or access token (JWT) sent by the client. For the S3 download requirement, the developer must configure an Amazon Cognito Identity Pool linked to the User Pool. The client submits the User Pool JWT to the Identity Pool, which returns temporary AWS credentials associated with an IAM role that grants read access to the S3 bucket.
Step-by-Step Solution
Key Concept
Distinguishing between Amazon Cognito User Pools (authentication and API authorization) and Identity Pools (AWS resource authorization via temporary credentials).