IAM policy example: run ECS tasks in one cluster, with a least privilege rewrite
Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.
Allows a deploy role to run and stop tasks in one ECS cluster, using the ecs:cluster condition key, and to pass the task role to ECS. The original allows ecs:* and iam:PassRole on all resources. Resource names and account 111122223333 are placeholders used in AWS documentation.
Open the workbench ยท All examples
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Ecs",
"Effect": "Allow",
"Action": [
"ecs:*",
"iam:PassRole"
],
"Resource": "*"
}
]
}
What it allows
- Allows every ECS action and passing any role to any service.
What it allows
Allow 93 actions (ecs:*, iam:PassRole) on every resource.
Action or pattern Actions Access levels ecs:*92 List 15, Read 20, Write 54, Permissions management 1, Tagging 2 iam:PassRole1 Write 1
Checks
- High Allows 56 write or permissions-management actions (1 permissions management) on every resource ("Resource": "*"). AWS documentation for this check
- High Allows iam:PassRole on every resource: the principal can pass any role, including more privileged ones, to a service. AWS documentation for this check
The action ecs:* covers 92 actions and PassRole on all roles lets a caller start a task with an administrator role.
Least privilege rewrite
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "RunInCluster",
"Effect": "Allow",
"Action": [
"ecs:RunTask",
"ecs:StopTask"
],
"Resource": "arn:aws:ecs:us-east-1:111122223333:task-definition/web-app:*",
"Condition": {
"ArnEquals": {
"ecs:cluster": "arn:aws:ecs:us-east-1:111122223333:cluster/prod"
}
}
},
{
"Sid": "PassTaskRole",
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::111122223333:role/web-app-task-role",
"Condition": {
"StringEquals": {
"iam:PassedToService": "ecs-tasks.amazonaws.com"
}
}
}
]
}
The rewrite limits tasks to one cluster and one task definition family, and passes one named role to ECS tasks only.
What it allows
Allow 2 actions (ecs:RunTask, ecs:StopTask) on arn:aws:ecs:us-east-1:111122223333:task-definition/web-app:* when ecs:cluster ArnEquals arn:aws:ecs:us-east-1:111122223333:cluster/prod.
Action or pattern Actions Access levels ecs:RunTask1 Write 1 ecs:StopTask1 Write 1 Allow 1 action (iam:PassRole) on arn:aws:iam::111122223333:role/web-app-task-role when iam:PassedToService StringEquals ecs-tasks.amazonaws.com.
Action or pattern Actions Access levels iam:PassRole1 Write 1
Checks
No flags from the six checks.
Related pages
Sources
- Amazon ECS Developer Guide: identity-based policy examples, read 16 Nov 2026
- IAM User Guide: grant a user permissions to pass a role, read 16 Nov 2026
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026
Last reviewed 16 Nov 2026.