A developer is designing a serverless web application where users authenticate via an Amazon Cognito User Pool. The application must meet the following requirements:
1. Access a REST API hosted on Amazon API Gateway, where endpoints must be secured so that only authenticated users can access them with minimal validation latency and zero custom validation code.
2. Upload files directly to an Amazon S3 bucket into a user-specific prefix (s3://app-uploads/\${user_id}/) without routing the files through a backend server.
Which TWO configurations should the developer implement to meet these requirements?
- Configure a Cognito User Pool Authorizer on the API Gateway REST API, and pass the Cognito ID token in the request Authorization header.Cevap
- Create an Amazon Cognito Identity Pool with the User Pool configured as an identity provider, and assign an authenticated IAM role that grants access to the S3 bucket using the \${cognito-identity.amazonaws.com:sub} policy variable.Cevap
- CConfigure an API Gateway Lambda Authorizer that parses the client request and calls the Cognito Identity Provider GetUser API to validate the token on every method invocation.
- DApply an S3 bucket policy that uses the Amazon Cognito User Pool ARN as the Principal to authorize upload actions based on the cognito:username claim.
- EEnable IAM authorization on the API Gateway REST API, and configure the client to pass the raw Cognito User Pool access token in the Authorization header.
Cevap
Configure a Cognito User Pool Authorizer on the API Gateway REST API, and create a Cognito Identity Pool to obtain temporary AWS credentials mapped to an IAM policy that uses the client's identity ID prefix.
To secure the API Gateway REST API with zero custom code and low latency, a native Cognito User Pool Authorizer is configured to inspect the Authorization header and validate the ID token locally. To authorize direct uploads to S3, a Cognito Identity Pool is required to act as the credential broker. The client exchanges the User Pool token for temporary AWS credentials. By associating the authenticated IAM role of the Identity Pool with a policy that limits access using the identity ID context variable, users are securely restricted to their own folders.
Adım Adım Çözüm
Anahtar Kavram
Integrating Amazon Cognito User Pools for API Gateway authentication and Cognito Identity Pools for S3 authorization.
Tahmini Süre:3m 0s