Nate
10/16/2025, 3:47 PMMarvin
10/16/2025, 3:47 PMresearch_prefect_topic
📊 Tools used:
• explore_module_offerings (1x)
• research_prefect_topic (1x)Nate
10/16/2025, 5:11 PMMarvin
10/16/2025, 5:11 PMMarvin
10/16/2025, 5:11 PMNate
10/16/2025, 5:12 PMMarvin
10/16/2025, 5:12 PMMarvin
10/16/2025, 5:39 PMprefect init (choose an ECS/Docker/Kubernetes recipe if you want a container build baked in)
- Commit the generated config
- In CI:
- Authenticate to Prefect Cloud: prefect cloud login --key $PREFECT_API_KEY --workspace $PREFECT_WORKSPACE
- Optionally build and push your Docker image (tag with the git SHA)
- Call prefect deploy from the repo root. It reads your prefect.yaml and creates/updates deployments.
2) Code-driven deployments from CI (Flow.from_source(...).deploy(...))
- Best when you want a central “deployment job” that can deploy any repo/flow without cloning or when you prefer explicit control in code
- Steps:
- In CI, run a tiny Python script that:
- points to your Git repo (or package storage)
- sets the entrypoint
- targets the work pool (ECS/Kubernetes/Docker)
- sets the image, parameters, schedules, etc.
Below are minimal GitHub Actions examples for both approaches. They assume:
- Prefect Cloud with secrets PREFECT_API_KEY and PREFECT_WORKSPACE
- ECS work pool already created and a worker running
- You build/push an image per commit and want that image in the deployment
A) GitHub Actions using prefect deploy
name: Deploy Prefect flows
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Prefect
run: pip install "prefect[aws]"
- name: Authenticate to Prefect Cloud
run: prefect cloud login --key "$PREFECT_API_KEY" --workspace "$PREFECT_WORKSPACE"
env:
PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
PREFECT_WORKSPACE: ${{ secrets.PREFECT_WORKSPACE }}
# Optional: build and push your image (ECR example)
- name: Configure AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: my-prefect-flows
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
# Deploy using repo config
- name: Deploy
run: |
# `prefect.yaml` should define deployments and target your ECS work pool.
# If your recipe supports it, you can set image via env or directly in the config.
prefect deploy
B) GitHub Actions using Flow.from_source(...).deploy(...)
```
name: Deploy Prefect flows (code-driven)
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Prefect
run: pip install "prefect[aws]"
- name: Authenticate to Prefect Cloud
run: prefect cloud login --key "$PREFECT_API_KEY" --workspace "$PREFECT_WORKSPACE"
env:
PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
PREFECT_WORKSPACE: ${{ secrets.PREFECT_WORKSPACE }}
# Optional: build/push image (same as above)
- name: Configure AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}Marvin
10/16/2025, 5:39 PMprefect worker start -p <pool-name>
- You can create or update a pool in CI with prefect work-pool create "<pool-name>" --type <ecs|kubernetes|docker> --overwrite if you want to manage it as code.
- Image build strategy
- Tag images with the git SHA; pass that tag to your deployment to guarantee reproducibility.
- Cache layers in CI to speed up builds.
- For ECS, push to ECR and reference that image in the deployment.
- Secrets and auth
- Prefect Cloud: use prefect cloud login --key ... --workspace ...
- Prefect Server: set PREFECT_API_URL in CI instead of logging in.
- When to use which approach
- Use prefect deploy if your repo already contains deployment config (e.g., from prefect init) and you want “convention over configuration”.
- Use Flow.from_source(...).deploy(...) if you prefer a single CI job that deploys multiple flows or repos, or you want full control in code without relying on on-disk project files.
If you share:
- Prefect Cloud vs Server
- Your work pool type (sounds like ECS)
- Which registry you use for images
- Whether you want the deployment name to track branches/SHAs
…I can tailor the exact CI YAML and, for ECS, suggest the right job_variables that match your task definition and networking.