A developer is implementing a mobile application that uses an Amazon Cognito identity pool to grant users temporary AWS credentials for uploading files to an Amazon S3 bucket. The developer has created an IAM role for authenticated users, but when the mobile application attempts to exchange the Cognito identity token for temporary credentials, the request fails with an access denied error. The developer reviews the trust policy currently attached to the IAM role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "cognito-identity.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud": "us-east-1:12345678-1234-1234-1234-1234567890ab"
},
"ForAnyValue:StringLike": {
"cognito-identity.amazonaws.com:amr": "authenticated"
}
}
}
]
}
Which modification to the trust policy will resolve this issue?
- AChange the Action to sts:AssumeRoleWithWebIdentity, but leave the Principal as a Service principal.
- BChange the Principal key to Federated with the value set to cognito-identity.amazonaws.com, but leave the Action as sts:AssumeRole.
- Change the Principal key to Federated and set its value to cognito-identity.amazonaws.com, and change the Action to sts:AssumeRoleWithWebIdentity.Answer
- DRemove the trust policy from the role and configure the mobile application SDK with the hardcoded Access Key ID and Secret Access Key of a dedicated IAM user.