Skip to main content
Your production application runs on AWS ECS Fargate. Resources are defined in infra/prd_resources.py.

Prerequisites

Before deploying, complete these steps:
StepGuideWhy
Configure secretsSecretsAPI keys and database password
Configure settingsSettingsRegion, subnets, image repo
Create ECR repositoryBelowStore your Docker images

Deploy to AWS

Once prerequisites are complete:
ag infra up prd: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 /ecs/{infra_name}-prd --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-service \
  --query 'services[0].{status:status,running:runningCount,desired:desiredCount}'

ECR Authentication

If you haven’t set up ECR yet, see Getting Started - AWS Setup.
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:
./scripts/auth_ecr.sh

Update Deployments

After making changes to your code or configuration:

Rebuild and push image

ag infra up prd:docker

Update task definition

Required when you change: image, CPU, memory, or environment variables.
ag infra patch prd:aws:::td

Update service

Triggers a new deployment with the latest task definition:
ag infra patch prd:aws:::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:
SettingLocationDefault
CPUprd_fastapi1024 (1 vCPU)
Memoryprd_fastapi2048 (2 GB)
Task countecs_service_count1
Health check pathhealth_check_path/health
Example customization:
prd_resources.py
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 prd:aws:::td && ag infra patch prd:aws:::service

Stop Deployment

To remove all AWS resources:
ag infra down prd:aws
This deletes everything including the database. Back up your data first.