Skip to content
IAM Policy Generator

IAM policy example: run ECS tasks in one cluster, with a least privilege rewrite

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

  1. Allow 93 actions (ecs:*, iam:PassRole) on every resource.

    Action or patternActionsAccess levels
    ecs:*92List 15, Read 20, Write 54, Permissions management 1, Tagging 2
    iam:PassRole1Write 1

Checks

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

  1. 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 patternActionsAccess levels
    ecs:RunTask1Write 1
    ecs:StopTask1Write 1
  2. 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 patternActionsAccess levels
    iam:PassRole1Write 1

Checks

No flags from the six checks.

Sources

  1. Amazon ECS Developer Guide: identity-based policy examples, read 16 Nov 2026
  2. IAM User Guide: grant a user permissions to pass a role, read 16 Nov 2026
  3. AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026

Last reviewed 16 Nov 2026.