Madushan Pathirana
08/18/2025, 3:54 PMMarvin
08/18/2025, 3:54 PMNate
08/18/2025, 3:56 PMprefect deploy
or calls .deploy
has to have PREFECT_API_URL
set (and the auth string if you set that up)Nate
08/18/2025, 3:57 PMMarvin
08/18/2025, 4:00 PMexport PREFECT_API_URL="<https://your-prefect-server.your-domain/api>"
# or persist in a profile:
prefect config set PREFECT_API_URL="$PREFECT_API_URL"
Docs: Server CLI / config
2) Pick and create a work pool
- If you want ECS tasks per flow run (common on AWS): use the ECS worker (provided by prefect-aws).
- Other options are Docker or Kubernetes workers if that’s where you run.
Create the pool (one-time):
uv run --with 'prefect[aws]' prefect work-pool create "ecs-pool" --type ecs
ECS guide: ECS worker guide
3) Run a worker (as a service)
Run a long‑lived worker that polls your pool. On ECS Fargate, run a service with the command:
uv run --with 'prefect[aws]' prefect worker start -p ecs-pool
Give the task a role that can launch ECS tasks and pull images, etc. (AmazonECSTaskExecutionRolePolicy + your cluster permissions).
4) Register deployments in CI
Do this on every merge/tag as part of your pipeline. Two common patterns:
- Programmatic (simple and explicit)
pip install "prefect[aws]"
python - << 'PY'
from prefect.flows import Flow
Flow.from_source(
source="<https://github.com/your-org/your-repo.git>",
entrypoint="flows/my_flow.py:my_flow",
).deploy(
name="prod",
work_pool_name="ecs-pool",
tags=["prod"]
)
PY
Notes:
- For private repos, use a token/SSH or a CI-provided checkout URL.
- You can run multiple deploy() calls for multiple flows.
- CLI (from a Prefect project)
If your repo is a Prefect project with a prefect.yaml, just:
prefect deploy
Or specify a single flow entrypoint:
prefect deploy flows/my_flow.py:my_flow --name prod --pool ecs-pool
CLI help: Server CLI
5) (Optional) Trigger runs in CI
prefect deployment run "my_flow/prod" --watch
A few practical tips
- Images vs. source: With the ECS worker, you’ll usually build/push a Docker image in CI and configure the work pool’s base job template to use that image. If you prefer pulling code from git at run time, keep your image generic and use Flow.from_source(...) as above.
- Networking: If your Server is private, run CI inside the VPC or use a self‑hosted runner with access.
- Versions: This assumes Prefect 3.x. Avoid 2.x commands like prefect deployment build
or Deployment.build_from_flow()
.
Want a concrete GitHub Actions example (build image, update ECS pool template, register deployment)? I can sketch it out with your repo name and ECS cluster/task details.