A developer is preparing to deploy a containerized financial API to Amazon ECS using the AWS Fargate launch type. The API application code utilizes the AWS SDK to decrypt sensitive transaction payloads at runtime using a customer managed key in AWS KMS. Additionally, the ECS agent must pull the API container image from a private Amazon ECR repository and send stdout/stderr logs to Amazon CloudWatch Logs. Which two IAM configuration steps must the developer perform to grant the necessary permissions? (Select TWO.)
- Attach a policy allowing the kms:Decrypt action to the IAM role configured as the Task Role in the task definition.Answer
- Attach a policy allowing the ecr:BatchGetImage and logs:PutLogEvents actions to the IAM role configured as the Task Execution Role in the task definition.Answer
- CAttach a policy allowing the kms:Decrypt action to the IAM role configured as the Task Execution Role in the task definition.
- DModify the trust policy of the Task Role to trust the Amazon EC2 service principal (ec2.amazonaws.com) to assume the role.
- EAttach a policy allowing the logs:PutLogEvents and logs:CreateLogStream actions to the IAM role configured as the Task Role in the task definition.
Answer
The developer must attach a policy allowing the kms:Decrypt action to the Task Role, and attach a policy allowing the ecr:BatchGetImage and logs:PutLogEvents actions to the Task Execution Role.
The application code uses the AWS SDK to decrypt payloads at runtime, which requires the ECS Task Role to have permissions for the kms:Decrypt action. On the other hand, pulling the image from Amazon ECR and writing logs to CloudWatch are operations executed by the ECS agent on the host, meaning the ECS Task Execution Role must have permissions for ECR image pull actions and CloudWatch Logs stream creation/log ingestion.
Step-by-Step Solution
Key Concept
Delineation between ECS Task Role and ECS Task Execution Role