<@ULVA73B9P> if i deploy prefect server using dock...
# ask-marvin
m
@Marvin if i deploy prefect server using docker compose in aws ecs, how to deploy flows to server when i do cicd?
m
âś… thought for 369.1 seconds
n
how you run the server shouldn't matter so much, just the python process that runs
prefect deploy
or calls
.deploy
has to have
PREFECT_API_URL
set (and the auth string if you set that up)
👍 1
m
Short answer: you don’t “push code to the server.” In Prefect 3.x you register deployments with your self‑hosted Server (metadata only) and have workers pick up runs and execute your code. Your CI job talks to your Server API, creates/updates deployments, and your worker(s) in AWS do the running. Here’s the blueprint that works well with ECS. 1) Point CI at your Server Make sure your CI runner can reach your Prefect Server API and set PREFECT_API_URL.
Copy code
export 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):
Copy code
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:
Copy code
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)
Copy code
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:
Copy code
prefect deploy
Or specify a single flow entrypoint:
Copy code
prefect deploy flows/my_flow.py:my_flow --name prod --pool ecs-pool
CLI help: Server CLI 5) (Optional) Trigger runs in CI
Copy code
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.