Let me provide a comprehensive solution since this involves multiple IAM components that all need to align correctly.
IAM Execution Role Setup:
Your task execution role needs three key permission sets. First, verify the trust policy allows ECS to assume the role:
{
"Effect": "Allow",
"Principal": {"Service": "ecs-tasks.amazonaws.com"},
"Action": "sts:AssumeRole"
}
ECR Image Permissions:
The AWS managed policy AmazonECSTaskExecutionRolePolicy covers basic ECR access, but if you’re using KMS encryption (which you are), add this inline policy:
{
"Effect": "Allow",
"Action": ["kms:Decrypt", "kms:DescribeKey"],
"Resource": "arn:aws:kms:us-east-1:123456789:key/your-key-id"
}
KMS Key Policy Configuration:
Your KMS key policy must also allow the execution role. Edit the key policy to include:
{
"Sid": "AllowECSTaskExecution",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::123456789:role/ecsTaskExecutionRole"},
"Action": ["kms:Decrypt", "kms:DescribeKey"],
"Resource": "*"
}
Task Definition Configuration:
Ensure your task definition properly references the execution role and includes logging for troubleshooting:
"executionRoleArn": "arn:aws:iam::123456789:role/ecsTaskExecutionRole",
"containerDefinitions": [{
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/my-app",
"awslogs-region": "us-east-1"
}
}
}]
Verification Checklist:
- Confirm execution role has AmazonECSTaskExecutionRolePolicy attached
- Add KMS decrypt permissions to execution role (inline policy)
- Update KMS key policy to allow execution role
- Verify ECR repository policy doesn’t restrict the role
- Check that image URI in task definition is correct and includes full path
- Enable CloudWatch Logs to see detailed error messages
Common Issues:
- Cross-account ECR access requires additional repository policies
- VPC endpoints for ECR must be configured if using private subnets without NAT
- Image tag must exist (“latest” might not be present)
- Region mismatch between ECR repository and Fargate task
After updating both the IAM role policy and KMS key policy, create a new task definition revision and launch a new task. The PENDING state should resolve within 30-60 seconds if permissions are correct. Monitor the stopped tasks section - if it still fails, the error message should now be more specific about what’s missing.
The key insight here is that KMS-encrypted ECR repositories require bidirectional permission grants: the IAM role needs KMS permissions, AND the KMS key policy must allow the role. Both must be configured or image pulls will fail.