An application running inside an Amazon ECS task on AWS Fargate in Account A () needs to write objects to an Amazon S3 bucket located in Account B (). The developer wants the application to temporarily assume an IAM role named CrossAccountS3Writer in Account B. The ECS task definition is configured with an ECS Task Role named ECSTaskRole.
The trust policy of the CrossAccountS3Writer role in Account B contains the following statement:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/ECSTaskRole"
},
"Action": "sts:AssumeRole"
}
]
}
When the application execution code attempts to call the sts:AssumeRole API, it fails with an AccessDenied error. How should the developer resolve this authorization failure?
- Attach an identity-based policy to ECSTaskRole in Account A that grants the sts:AssumeRole permission targeting the Amazon Resource Name (ARN) of the CrossAccountS3Writer role in Account B.Answer
- BAttach an identity-based policy to the ECS Task Execution Role in Account A that grants the sts:AssumeRole permission targeting the Amazon Resource Name (ARN) of the CrossAccountS3Writer role in Account B.
- CModify the trust policy of the CrossAccountS3Writer role in Account B to specify the ECS service principal ecs-tasks.amazonaws.com as the principal instead of the ECSTaskRole ARN.
- DGenerate long-term IAM access keys for a user in Account B, hardcode them into the application's client initialization code, and initialize the S3 client directly using those credentials.