David Martin Calalang
08/14/2025, 4:19 PMLabels
settings field in my ECS hosted work-pool to add tags to spawned ECS tasks for my flow deploymentsMarvin
08/14/2025, 4:19 PMMarvin
08/14/2025, 4:21 PMjob_variables
Most users just add a tags
section to the ECS worker’s job variables. Example defaults on your ECS work pool:
{
"cluster": "my-ecs-cluster",
"task_definition_arn": "arn:aws:ecs:us-east-1:123456789012:task-definition/my-task:42",
"network_configuration": {
"awsvpcConfiguration": {
"subnets": [
"subnet-abc",
"subnet-def"
],
"securityGroups": [
"sg-123"
],
"assignPublicIp": "ENABLED"
}
},
"tags": {
"Project": "analytics",
"Environment": "prod",
"Owner": "data-eng"
}
}
Per-deployment override (Prefect 3.x):
from prefect import flow
@flow
def my_flow():
...
if __name__ == "__main__":
(
my_flow
.from_source(
"<https://github.com/acme/prefect-flows>",
entrypoint="flows/my_flow.py:my_flow",
)
.deploy(
name="prod",
work_pool_name="ecs-pool",
job_variables={
"tags": {
"Project": "analytics",
"Environment": "prod",
"Owner": "data-eng"
}
},
)
)
Notes and gotchas
- These “tags” are AWS ECS task tags; you’ll need IAM permissions that allow tagging on ecs:RunTask
(e.g., ecs:TagResource
via RunTask).
- If you already put tags on your Task Definition and want them on the Task, you can rely on ECS propagation if your setup supports it; otherwise pass tags directly as above.
- If you don’t see tags on the running task, double-check your pool’s “Default base job variables” and the deployment’s job_variables
(deployment overrides pool defaults).
Docs
- ECS worker guide: Prefect AWS ECS guide
If you share your current pool “Default base job variables,” I can point out exactly where to add the tags. Yes, I know, thrilling.David Martin Calalang
08/14/2025, 4:27 PMLabels
field in the work-pool settings page can be used to add tags, Prefect just adds them on top of the default ones they have when registering the task-runMarvin
08/14/2025, 4:27 PMMarvin
08/14/2025, 4:29 PMRunTask
.
- Any tags
you set in the ECS job variables are included and are the most explicit, predictable way to control AWS tags.
- If your worker is also propagating Work Pool labels, they’ll be merged “on top” of Prefect’s defaults; typically deployment job_variables.tags
should win on key conflicts.
Explicit, reliable way (pool defaults or per-deployment):
- Pool “Default base job variables”:
{
"tags": {
"Project": "analytics",
"Environment": "prod"
}
}
- Per-deployment:
from prefect import flow
@flow
def my_flow():
...
if __name__ == "__main__":
(
my_flow
.from_source(
"<https://github.com/acme/prefect-flows>",
entrypoint="flows/my_flow.py:my_flow",
)
.deploy(
name="prod",
work_pool_name="ecs-pool",
job_variables={
"tags": {
"Project": "analytics",
"Environment": "prod"
}
},
)
)
If you want to rely on Work Pool “Labels,” go ahead and add them there; they should be merged with Prefect’s defaults at task submission. If you can share a quick example of the resulting tag keys/values you see in AWS (or your Prefect version), I’ll document the exact mapping and precedence for you. Until then, job_variables.tags
remains the most explicit way to guarantee AWS tags.
Docs for reference:
- ECS worker guide: Prefect AWS ECS guide