Your production application runs on AWS ECS Fargate. Resources are defined in infra/prd_resources.py.
Prerequisites
Before deploying, complete these steps:
| Step | Guide | Why |
|---|
| Configure secrets | Secrets | API keys and database password |
| Configure settings | Settings | Region, subnets, image repo |
| Create ECR repository | Below | Store your Docker images |
Deploy to AWS
Once prerequisites are complete:
ag infra up --env prd --infra aws
This creates:
- Docker image pushed to ECR
- RDS PostgreSQL instance
- ECS Cluster, Service, and Task Definition
- Application Load Balancer with Target Group
- AWS Secrets Manager entries
RDS takes about 5 minutes to provision. You can monitor progress in the AWS
Console.
Verify Deployment
After deployment completes, verify everything is working:
Check the health endpoint
Get your load balancer DNS from the AWS Console (EC2 → Load Balancers), then:
curl http://[LOAD_BALANCER_DNS]/health
Expected response:
{ "status": "ok", "instantiated_at": "2025-01-01T12:00:00Z" }
Check CloudWatch logs
aws logs tail {infra_name}-prd-api --follow
Look for Application startup complete to confirm the app started.
Check ECS service status
aws ecs describe-services \
--cluster {infra_name}-prd \
--services {infra_name}-prd-api-service \
--query 'services[0].{status:status,running:runningCount,desired:desiredCount}'
ECR Authentication
ECR tokens expire after 12 hours. Re-authenticate before pushing:
aws ecr get-login-password --region us-east-1 | \
docker login --username AWS --password-stdin \
[ACCOUNT_ID].dkr.ecr.us-east-1.amazonaws.com
Or use the helper script:
Update Deployments
After making changes to your code or configuration:
Rebuild and push image
ag infra up --env prd --infra docker
Update task definition
Required when you change: image, CPU, memory, or environment variables.
ag infra patch --env prd --infra aws --name td
Update service
Triggers a new deployment with the latest task definition:
ag infra patch --env prd --infra aws --name service
Shortcut: If you only rebuilt the image (no config changes), you can skip
the task definition update and just patch the service.
Customize Your Deployment
Edit infra/prd_resources.py to customize:
| Setting | Location | Default |
|---|
| CPU | prd_fastapi | 1024 (1 vCPU) |
| Memory | prd_fastapi | 2048 (2 GB) |
| Task count | ecs_service_count | 1 |
| Health check path | health_check_path | /health |
Example customization:
prd_fastapi = FastApi(
...
ecs_task_cpu="2048", # 2 vCPU
ecs_task_memory="4096", # 4 GB
ecs_service_count=2, # 2 tasks for redundancy
)
After changes, update the task definition and service:
ag infra patch --env prd --infra aws --name td && ag infra patch --env prd --infra aws --name service
Stop Deployment
To remove all AWS resources:
ag infra down --env prd --infra aws
This deletes everything including the database. Back up your data first.