A developer is implementing fine-grained access control for a mobile application. Users authenticate via an Amazon Cognito User Pool, and the application needs to write user-specific profile data to an Amazon DynamoDB table named `UserProfiles`. The table's partition key is `UserId` (String). The developer created an Amazon Cognito Identity Pool to provide temporary AWS credentials to authenticated users and attached an IAM policy to the authenticated role that uses the `dynamodb:LeadingKeys` condition. However, when the application attempts to write data to the DynamoDB table, the API calls fail with an `AccessDeniedException` error. Which two actions must the developer take to resolve these authorization failures?
- Configure the application to exchange the Cognito User Pool tokens for temporary AWS credentials from the Cognito Identity Pool, and use these credentials to sign the DynamoDB requests.Answer
- Ensure that the partition key `UserId` value in the DynamoDB write request is set to the user's Cognito Identity ID.Answer
- CModify the trust policy of the authenticated IAM role to restrict the `dynamodb:LeadingKeys` condition to the Cognito identity provider.
- DAssociate the IAM permission policy allowing `dynamodb:PutItem` directly to the Cognito User Pool's App Client configuration.
- EEmbed static IAM credentials directly into the application's SDK client configuration to bypass the Cognito Identity Pool exchange.
Answer
To resolve the authorization failures, the application must exchange the Cognito User Pool tokens for temporary AWS credentials from the Cognito Identity Pool and use those credentials to sign the requests. Additionally, the partition key value in the DynamoDB write request must match the user's Cognito Identity ID.
To resolve the authorization failure, the developer must ensure that the mobile application properly coordinates authentication and authorization. First, the application must exchange the Cognito User Pool token for temporary AWS credentials using the Cognito Identity Pool, as the User Pool token alone does not grant direct AWS service access. Second, the write request to DynamoDB must use the user's Cognito Identity ID as the partition key value to satisfy the `dynamodb:LeadingKeys` condition in the IAM permissions policy.
Step-by-Step Solution
Key Concept
Using Amazon Cognito Identity Pools and DynamoDB Fine-Grained Access Control (FGAC) to securely authorize mobile applications to access AWS services.
Estimated Time:1m 30s