Madushan Pathirana
08/23/2025, 2:32 AMMarvin
08/23/2025, 2:32 AMMarvin
08/23/2025, 2:36 AMprefect work-pool create dev --type docker
prefect work-pool create prod --type docker
- Start workers (include Docker extra if needed):
uv run --with 'prefect[docker]' prefect worker start -p dev
uv run --with 'prefect[docker]' prefect worker start -p prod
- Deploy a flow to an environment-specific pool/image:
from prefect import flow
from prefect.flows import Flow
Flow.from_source(
"<https://github.com/your-org/your-repo>",
"flows/etl.py:etl_flow",
).deploy(
name="etl-dev",
work_pool_name="dev",
image="<http://123456789012.dkr.ecr.us-east-1.amazonaws.com/etl:dev|123456789012.dkr.ecr.us-east-1.amazonaws.com/etl:dev>",
)
Additional tips:
- Use separate AWS IAM roles, ECR repos or distinct tags, S3 buckets/prefixes per env.
- Manage env-specific config via Prefect profiles/variables or your secret manager (e.g., AWS Secrets Manager).
- Put the Server behind an ALB with TLS; keep the DB and result storage outside the EC2 instance.
Docs and references:
- Prefect Server concepts: Server (Prefect 3.x)
- Work pools and workers overview: Work pools & workers blog
- Settings and profiles: Settings & profiles
If you share your isolation requirements (RBAC, network separation, upgrade cadence), I can recommend single- vs multi-Server more definitively and sketch a tailored AWS diagram.Madushan Pathirana
08/23/2025, 2:52 AMMarvin
08/23/2025, 2:52 AMMarvin
08/23/2025, 2:53 AMMarvin
08/23/2025, 3:05 AMMarvin
08/23/2025, 3:06 AMMadushan Pathirana
08/25/2025, 11:01 AMMarvin
08/25/2025, 11:01 AMMarvin
08/25/2025, 11:08 AMasyncpg
driver is installed on your EC2 host:
pip install asyncpg
- Set Prefect database settings via environment variables (recommended for server processes). Use the async driver `postgresql+asyncpg`:
Option A: Set individual fields
export PREFECT_SERVER_DATABASE_DRIVER=postgresql+asyncpg
export PREFECT_SERVER_DATABASE_HOST=<your-rds-endpoint>
export PREFECT_SERVER_DATABASE_PORT=5432
export PREFECT_SERVER_DATABASE_USER=<username>
export PREFECT_SERVER_DATABASE_PASSWORD=<password>
export PREFECT_SERVER_DATABASE_NAME=<database>
# Optional SQLAlchemy pool tuning
export PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_SIZE=10
export PREFECT_SERVER_DATABASE_SQLALCHEMY_MAX_OVERFLOW=10
export PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_RECYCLE=3600
export PREFECT_SERVER_DATABASE_SQLALCHEMY_POOL_TIMEOUT=30
# Enable TLS to RDS (recommended)
export PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_ENABLED=true
export PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_CA_FILE=/path/to/aws-rds-ca.pem
# Optional, if you use client certs (not typical for RDS):
# export PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_CERT_FILE=/path/to/client-cert.pem
# export PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_KEY_FILE=/path/to/client-key.pem
# export PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_CHECK_HOSTNAME=true
# Migrate DB schema automatically on server start (default is true)
export PREFECT_SERVER_DATABASE_MIGRATE_ON_START=true
Option B: Use a full connection URL
export PREFECT_SERVER_DATABASE_CONNECTION_URL="postgresql+asyncpg://<user>:<pass>@<host>:5432/<db>"
# For TLS with asyncpg, prefer the TLS settings above over URL params.
Initialize/upgrade the database schema
- You can rely on PREFECT_SERVER_DATABASE_MIGRATE_ON_START=true
, or run an explicit upgrade:
prefect server database upgrade
Start the server
prefect server start
Running dev/stage/prod on the same EC2
- Use separate Prefect profiles and separate RDS databases (or schemas) for isolation. For example:
prefect profile create dev && prefect profile use dev
prefect config set PREFECT_SERVER_DATABASE_NAME=prefect_dev
prefect profile create stage && prefect profile use stage
prefect config set PREFECT_SERVER_DATABASE_NAME=prefect_stage
prefect profile create prod && prefect profile use prod
prefect config set PREFECT_SERVER_DATABASE_NAME=prefect_prod
- If you run multiple servers concurrently on the same host, set unique API ports per profile and bind addresses to avoid conflicts (e.g., PREFECT_SERVER_API_PORT
), and ensure each points to its own RDS DB.
References
- Self-hosted guide: Prefect 3 self-hosted
- Settings reference: Prefect 3 settings reference
Questions
- Do you want me to provide a minimal systemd unit or docker-compose example for the server with the RDS TLS config?
- Will you run multiple server instances at the same time on the EC2 host (one per env), or a single server with logical separation?