A developer is deploying a containerized application to Amazon Elastic Container Service (Amazon ECS) on AWS Fargate in Account A (). The application must assume an IAM role named `CrossAccountDynamoDBAccess` in Account B () to perform read operations on a DynamoDB table.
The task definition in Account A is configured with an ECS Task Role named `TaskRole` and an ECS Task Execution Role named `TaskExecutionRole`. The developer configures the trust policy for the `CrossAccountDynamoDBAccess` role in Account B as follows:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
When the container starts, the application throws an `AccessDenied` error when calling the AWS Security Token Service (STS) `AssumeRole` API.
How should the developer modify the configuration to resolve this issue and grant the application access using the principle of least privilege?
- Update the trust policy of `CrossAccountDynamoDBAccess` in Account B to specify the principal as `"AWS": "arn:aws:iam::111111111111:role/TaskRole"`. Additionally, attach a policy to `TaskRole` in Account A that allows `sts:AssumeRole` on the `CrossAccountDynamoDBAccess` role ARN.Answer
- BUpdate the trust policy of `CrossAccountDynamoDBAccess` in Account B to specify the principal as `"AWS": "arn:aws:iam::111111111111:role/TaskExecutionRole"`. Additionally, attach a policy to `TaskExecutionRole` in Account A that allows `sts:AssumeRole` on the `CrossAccountDynamoDBAccess` role ARN.
- CConfigure the application code to initialize the AWS SDK client using hardcoded AWS access keys of an IAM user created in Account A. Update the trust policy of `CrossAccountDynamoDBAccess` in Account B to specify the principal as the ARN of that IAM user.
- DModify the trust policy of `TaskRole` in Account A to specify the principal as `"AWS": "arn:aws:iam::222222222222:role/CrossAccountDynamoDBAccess"`. Attach a policy to `CrossAccountDynamoDBAccess` in Account B that allows `sts:AssumeRole` on `TaskRole`.