docs/integrations/prefect-aws/ecs-worker/index.mdx
ECS (Elastic Container Service) is an excellent choice for executing Prefect flow runs in production environments:
ECS workers operate within your AWS infrastructure, providing secure and scalable flow execution. Prefect enables remote flow execution via workers and work pools - to learn more about these concepts see the deployment docs.
%%{
init: {
'theme': 'neutral',
'themeVariables': {
'margin': '10px'
}
}
}%%
flowchart TB
subgraph ecs_cluster[ECS Cluster]
subgraph ecs_service[ECS Service]
td_worker[Worker Task Definition] --> |defines| prefect_worker[Prefect Worker]
end
prefect_worker -->|kicks off| ecs_task
fr_task_definition[Flow Run Task Definition]
subgraph ecs_task[ECS Task Execution]
flow_run((Flow Run))
end
fr_task_definition -->|defines| ecs_task
end
subgraph prefect_cloud[Prefect Cloud]
work_pool[ECS Work Pool]
end
subgraph github[ECR]
flow_code["Flow Code"]
end
flow_code --> |pulls| ecs_task
prefect_worker -->|polls| work_pool
work_pool -->|configures| fr_task_definition
ecs work pools are executed as ECS tasksAn ECS task is not the same as a Prefect task. ECS tasks are groupings of containers that run within an ECS Cluster, defined by task definitions. They're ideal for ephemeral processes like Prefect flow runs. </Tip>
prefect-aws CLIThe fastest way to deploy production-ready ECS workers is by using the prefect-aws CLI:
prefect-aws ecs-worker deploy-service \
--work-pool-name my-ecs-pool \
--stack-name prefect-ecs-worker \
--existing-cluster-identifier my-ecs-cluster \
--existing-vpc-id vpc-12345678 \
--existing-subnet-ids subnet-12345,subnet-67890 \
--prefect-api-url https://api.prefect.cloud/api/accounts/.../workspaces/... \
--prefect-api-key your-api-key
This command creates a CloudFormation stack that provisions all the infrastructure required for a production-ready ECS worker service.
<Tip> **Pinning worker image versions**By default, the CLI uses prefecthq/prefect-aws:latest which includes both prefect and prefect-aws pre-installed. For more control over versions in production or to use a custom image, use the --docker-image flag:
prefect-aws ecs-worker deploy-service \
--docker-image prefecthq/prefect-aws:0.7.5-python3.12-prefect3.6.20 \
--work-pool-name my-ecs-pool \
...
This ensures your worker uses specific versions of both prefect-aws and prefect, preventing unexpected behavior from automatic updates.
</Tip>
Key benefits:
Additional CLI commands:
prefect-aws ecs-worker list - View all deployed stacksprefect-aws ecs-worker status <stack-name> - Check deployment statusprefect-aws ecs-worker delete <stack-name> - Clean up infrastructureprefect-aws ecs-worker export-template - Export CloudFormation templates for customizationFor detailed CLI options run prefect-aws ecs-worker deploy-service --help.
For users who want full control over their ECS infrastructure setup:
Deploy manually → Step-by-step guide for creating ECS clusters, task definitions, and configuring workers from scratch.
Before deploying ECS workers, ensure you have: