An application team is deploying a containerized API to Amazon ECS using the AWS Fargate launch type. The application code needs to retrieve operational parameters from Amazon DynamoDB during runtime. Additionally, the ECS agent must retrieve database credentials from AWS Secrets Manager to configure the application's environment variables before the container starts. Which configuration will allow the application to start and run successfully with the least privilege?
- AConfigure the ECS Task Execution Role with permissions for both dynamodb:GetItem and secretsmanager:GetSecretValue, leaving the Task Role empty.
- BConfigure the ECS Task Role with permissions for dynamodb:GetItem and the Task Execution Role with permissions for secretsmanager:GetSecretValue, and configure the trust policy of both roles to trust the ecs.amazonaws.com service principal.
- Configure the ECS Task Role with permissions for dynamodb:GetItem and the ECS Task Execution Role with permissions for secretsmanager:GetSecretValue, and configure the trust policy of both roles to trust the ecs-tasks.amazonaws.com service principal.Answer
- DConfigure the ECS Task Execution Role to read credentials from AWS Secrets Manager, and hardcode the AWS access keys in the application's initialization code to access the DynamoDB table.
Answer
Configure the ECS Task Role with permissions for dynamodb:GetItem, the ECS Task Execution Role with permissions for secretsmanager:GetSecretValue, and configure both roles to trust the ecs-tasks.amazonaws.com service principal.
The correct configuration assigns DynamoDB permissions to the ECS Task Role and Secrets Manager permissions to the ECS Task Execution Role, while setting the trust policy of both roles to trust the ecs-tasks.amazonaws.com service principal. This separates responsibilities: the Task Execution Role allows the ECS agent to prepare the container environment (including resolving environment variables from Secrets Manager), while the Task Role gives the running containerized application the temporary AWS credentials it needs to perform DynamoDB API operations.
Step-by-Step Solution
Key Concept
Amazon ECS IAM Roles Separation (Task Role vs Task Execution Role)