> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Production Deployment

> Deploy your application to AWS with ECS Fargate

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](/deploy/templates/aws/configure/secrets)         | API keys and database password |
| Configure settings    | [Settings](/deploy/templates/aws/configure/infra-settings) | Region, subnets, image repo    |
| Create ECR repository | [Below](#create-an-ecr-repository)                         | Store your Docker images       |

## Deploy to AWS

Once prerequisites are complete:

<CodeGroup>
  ```bash Full Options theme={null}
  ag infra up --env prd --infra aws
  ```

  ```bash Shorthand theme={null}
  ag infra up prd:aws
  ```
</CodeGroup>

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

<Note>
  RDS takes about 5 minutes to provision. You can monitor progress in the AWS
  Console.
</Note>

## 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:

```bash theme={null}
curl http://[LOAD_BALANCER_DNS]/health
```

Expected response:

```json theme={null}
{ "status": "ok", "instantiated_at": "2025-01-01T12:00:00Z" }
```

### Check CloudWatch logs

```bash theme={null}
aws logs tail {infra_name}-prd-api --follow
```

Look for `Application startup complete` to confirm the app started.

### Check ECS service status

```bash theme={null}
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

<Note>
  If you haven't set up ECR yet, see [Deploy - AWS
  Setup](/deploy/templates/aws/deploy#step-1-aws-setup).
</Note>

ECR tokens expire after 12 hours. Re-authenticate before pushing:

```bash theme={null}
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:

```bash theme={null}
./scripts/auth_ecr.sh
```

## Update Deployments

After making changes to your code or configuration:

### Rebuild and push image

<CodeGroup>
  ```bash Full Options theme={null}
  ag infra up --env prd --infra docker
  ```

  ```bash Shorthand theme={null}
  ag infra up prd:docker
  ```
</CodeGroup>

### Update task definition

Required when you change: image, CPU, memory, or environment variables.

<CodeGroup>
  ```bash Full Options theme={null}
  ag infra patch --env prd --infra aws --name td
  ```

  ```bash Shorthand theme={null}
  ag infra patch prd:aws::td
  ```
</CodeGroup>

### Update service

Triggers a new deployment with the latest task definition:

<CodeGroup>
  ```bash Full Options theme={null}
  ag infra patch --env prd --infra aws --name service
  ```

  ```bash Shorthand theme={null}
  ag infra patch prd:aws::service
  ```
</CodeGroup>

<Note>
  **Shortcut:** If you only rebuilt the image (no config changes), you can skip
  the task definition update and just patch the service.
</Note>

## 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:

```python prd_resources.py theme={null}
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:

<CodeGroup>
  ```bash Full Options theme={null}
  ag infra patch --env prd --infra aws --name td && ag infra patch --env prd --infra aws --name service
  ```

  ```bash Shorthand theme={null}
  ag infra patch prd:aws::td && ag infra patch prd:aws::service
  ```
</CodeGroup>

## Stop Deployment

To remove all AWS resources:

<CodeGroup>
  ```bash Full Options theme={null}
  ag infra down --env prd --infra aws
  ```

  ```bash Shorthand theme={null}
  ag infra down prd:aws
  ```
</CodeGroup>

<Warning>
  This deletes everything including the database. Back up your data first.
</Warning>
