Two IAM roles can appear in an Amazon ECS task definition. The execution role authorizes the ECS agent to prepare and run the task. The task role authorizes AWS API calls made by code inside the containers. Keeping these roles separate makes an access error much easier to diagnose.
Match the permission to the caller
| Activity | Role to inspect |
|---|---|
ECS pulls a private Amazon ECR image or sends container logs through the awslogs driver |
Execution role |
| ECS injects a secret referenced in the task definition during startup | Execution role |
Application code calls GetSecretValue after startup |
Task role |
| Application code reads one configuration object from Amazon S3 | Task role |
The same AWS service can appear in either column. What matters is whether the ECS agent or the application makes the request. The execution role credentials are unavailable to the application container.
Inspect an existing task definition
Use a staging Fargate task definition and an AWS CLI identity allowed to describe it. Substitute your task family and Region.
aws ecs describe-task-definition \
--region us-east-1 --task-definition web:42 \
--query 'taskDefinition.{taskRole:taskRoleArn,executionRole:executionRoleArn,logging:containerDefinitions[].logConfiguration.logDriver}'
If the container reads an S3 configuration object at runtime, scope the task role’s policy to that object. In the example below, replace the bucket name and object key. This example assumes a same-account object with SSE-S3 encryption and sufficient bucket-policy access. SSE-KMS can also require permission to use the KMS key.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-staging-config/app/settings.json"
}]
}
Create the IAM roles with the ecs-tasks.amazonaws.com trusted service principal and the source restrictions appropriate to your account. Use an existing execution role with the required ECR, logs, and startup-secret permissions. Set both ARN fields in a new task definition revision and update the staging service. The identity registering the revision needs iam:PassRole for the roles being assigned.
Verify from the right place
Check the new deployment’s active task definition and confirm the container starts and writes logs. From the running staging container, use its configured AWS SDK or, if installed, the AWS CLI to verify the identity. The result should show the application task role rather than the execution role.
aws sts get-caller-identity --query Arn --output text
aws s3api head-object --region us-east-1 \
--bucket example-staging-config --key app/settings.json \
--query ContentLength
HeadObject checks that the workload can access the example object without printing its contents. It does not prove the application can parse the configuration. Exercise the application’s read path with a synthetic staging object to check that separately.
Investigate before expanding permissions
- The task fails before the app starts. Inspect the task stop reason. Check the execution role and network access to the registry, secrets service, or logs endpoint.
- The app runs and returns AccessDenied. Check the assumed task role, then the exact action, resource ARN, and any bucket policy or KMS policy needed by the request.
- The identity is unexpected. Check whether static credentials or a configured profile are taking precedence in the container. Keep credentials out of the image, task environment, and application logs.
Use dedicated staging roles for a rehearsal. Afterward, roll the staging service back to its original revision before removing roles or resources created exclusively for the lab.
See the AWS guides for task IAM roles, task execution roles, and Fargate task definition parameters.







Leave a Reply