# 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.

```json
{
  "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.

- Allows 93 actions (ecs:*, iam:PassRole) on every resource.

Checks:
- high: Allows 56 write or permissions-management actions (1 permissions management) on every resource ("Resource": "*"). (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
- high: Allows iam:PassRole on every resource: the principal can pass any role, including more privileged ones, to a service. (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html)

The action ecs:* covers 92 actions and PassRole on all roles lets a caller start a task with an administrator role.

## Least privilege rewrite

```json
{
  "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.

- Allows 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.
- Allows 1 action (iam:PassRole) on arn:aws:iam::111122223333:role/web-app-task-role when iam:PassedToService StringEquals ecs-tasks.amazonaws.com.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every Elastic Container Service action and its access level](/actions/ecs/)

## Related pages

- [IAM policy example: read EKS cluster details for kubeconfig](/examples/eks-describe-cluster-for-kubeconfig/)
- [IAM policy example: invoke one Bedrock foundation model](/examples/bedrock-invoke-one-model/)
- [IAM policy example: invoke Bedrock models with streaming](/examples/bedrock-invoke-with-streaming/)
- [All of them](/examples/)

## Sources

- Amazon ECS Developer Guide: identity-based policy examples: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/security_iam_id-based-policy-examples.html (read 16 Nov 2026)
- IAM User Guide: grant a user permissions to pass a role: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/ecs-run-tasks-in-one-cluster/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
