Madushan Pathirana
09/25/2025, 10:27 AMMarvin
09/25/2025, 10:27 AMMarvin
09/25/2025, 10:30 AM{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:RunTask",
"ecs:DescribeTasks",
"ecs:DescribeTaskDefinition",
"ecs:StopTask"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"iam:PassRole"
],
"Resource": [
"arn:aws:iam::<ACCOUNT_ID>:role/<YourECSTaskExecutionRole>",
"arn:aws:iam::<ACCOUNT_ID>:role/<YourECSTaskRole>"
]
},
{
"Effect": "Allow",
"Action": [
"ecs:RegisterTaskDefinition",
"ecs:DeregisterTaskDefinition"
],
"Resource": "*"
}
]
}
Docs: see the ECS guide for Prefect 3.x ECS guide
Notes:
- If you provide a pre‑created task definition ARN in your work pool, you can drop Register/DeregisterTaskDefinition from the worker’s permissions.
- Push work pools (which can involve SQS/EventBridge) are generally a Prefect Cloud feature; since you’re on Prefect Server, you’ll use workers (pull) and don’t need those services.
If you want, I can help tailor a minimal IAM policy for your EC2 launch type and RDS access.Madushan Pathirana
09/25/2025, 10:32 AMMarvin
09/25/2025, 10:32 AMMarvin
09/25/2025, 10:33 AM{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>"
},
"Action": "sts:AssumeRole"
}
]
}
- Attach AWS managed policy:
- AmazonECSTaskExecutionRolePolicy
- Optional inline policy (lets tasks create the log group if it doesn’t exist):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "*"
}
]
}
Attach this execution role to:
- Your Prefect Server Fargate service task
- Your ECS worker Fargate service task
- Flow-run tasks launched by the worker (via the work pool settings)
2) ECS worker task role (launches tasks)
- Trust policy (same as above):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>"
},
"Action": "sts:AssumeRole"
}
]
}
- Permissions policy (minimal to run/deregister/describe tasks and pass roles). You can start permissive and tighten later:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EcsControl",
"Effect": "Allow",
"Action": [
"ecs:RunTask",
"ecs:StopTask",
"ecs:DescribeTasks",
"ecs:DescribeTaskDefinition",
"ecs:RegisterTaskDefinition",
"ecs:DeregisterTaskDefinition",
"ecs:ListTasks",
"ecs:TagResource"
],
"Resource": "*"
},
{
"Sid": "PassRolesToFlowTasks",
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": [
"arn:aws:iam::<ACCOUNT_ID>:role/PrefectFargateExecutionRole",
"arn:aws:iam::<ACCOUNT_ID>:role/PrefectFlowRunTaskRole"
],
"Condition": {
"StringEquals": {
"iam:PassedToService": "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>"
}
}
}
]
}
Optional tightening for RunTask/StopTask to a specific cluster (if you want):
{
"Sid": "RestrictToCluster",
"Effect": "Allow",
"Action": [
"ecs:RunTask",
"ecs:StopTask"
],
"Resource": "*",
"Condition": {
"ArnEquals": {
"ecs:cluster": "arn:aws:ecs:<REGION>:<ACCOUNT_ID>:cluster/<CLUSTER_NAME>"
}
}
}
Attach this worker task role to:
- Your ECS worker Fargate service (this is the role the worker container uses)
3) Flow-run task role (what your flows run as)
- Trust policy (same as above):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>"
},
"Action": "sts:AssumeRole"
}
]
}
- Permissions policy:
- If your flows only need to reach RDS via username/password (managed by Prefect) and no AWS APIs, you can keep this empty (no inline permissions). Networking to RDS is handled by your VPC/subnet/SG config, not IAM.
- If flows need AWS APIs (e.g., S3), add those here later.
How to wire this in Prefect (no SQS/EventBridge):
- Prefect Server service task: use the shared execution role; task role can be minimal/empty unless Server needs AWS APIs.
- ECS worker service task: use the shared execution role + the ECS worker task role (above).
- Prefect ECS work pool base job template (in the UI): set the executionRoleArn to the shared execution role and the taskRoleArn to PrefectFlowRunTaskRole. Also set cluster, subnets, security groups, and launch type FARGATE.
Reference docs:Marvin
09/25/2025, 10:33 AMMadushan Pathirana
09/25/2025, 10:35 AMMarvin
09/25/2025, 10:35 AMMarvin
09/25/2025, 10:36 AM