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

# Deploy Backtale on AWS

> Mirror the public image into ECR, then apply the AWS Terraform pack for App Runner and private RDS PostgreSQL.

The AWS pack lives at `deploy/terraform/aws` on `main` of the product repository, and in the license zip. It creates a VPC, private RDS for PostgreSQL, an ECR repository, and an App Runner service with HTTPS on port 3000. App Runner pulls from ECR only, so you mirror the public GitHub Container Registry image once. No GHCR login.

## Before apply

* AWS credentials that can create VPC, RDS, ECR, IAM, and App Runner
* Terraform 1.5 or later, Docker, and the AWS CLI
* The digest and `cosign.pub`. [Verify the image](https://docs.backtale.app/install/verify.md) before you mirror it.

## Apply

**1. Set variables**

```bash theme={null}
cp terraform.tfvars.example terraform.tfvars
```

```hcl theme={null}
image_digest = "sha256:a4b6216589d14bd4be4deb7db4ed2f81ad28f65b76475135d741bab4c0d8721a"
app_base_url = "https://backtale.example.com"
```

`license_file_path` is not mounted.

**2. Create the ECR repository and mirror the digest**

```bash theme={null}
terraform init
terraform apply -target=aws_ecr_repository.this
chmod +x mirror-image.sh
./mirror-image.sh sha256:a4b6216589d14bd4be4deb7db4ed2f81ad28f65b76475135d741bab4c0d8721a "$(terraform output -raw ecr_repository_url)"
```

`mirror-image.sh` checks that the argument matches `sha256:` plus 64 hex digits, pulls `ghcr.io/rahilp/backtale@<digest>` with no GHCR login, and pushes that image to your ECR repository. Set `AWS_REGION` if the CLI has no default region.

**3. Create the rest**

```bash theme={null}
terraform apply
```

Set `app_base_url` to the `apprunner_service_url` output (or your custom domain) and apply again.

**4. Enable pgvector and finish setup**

Connect to RDS (bastion, SSM port-forward, or a temporary jump host) and run:

```sql theme={null}
CREATE EXTENSION IF NOT EXISTS vector;
```

Open `https://<apprunner_service_url>/setup` with `terraform output -raw auth_setup_token`. Store `terraform output -raw token_encryption_key` outside AWS. After [First run](https://docs.backtale.app/install/first-run.md), delete the `AUTH_SETUP_TOKEN` parameter and remove it from the App Runner service, then deploy a new revision.

Secrets Terraform writes: SSM SecureString parameters for `DATABASE_URL`, `DIRECT_URL` (`sslmode=require`), `TOKEN_ENCRYPTION_KEY`, and `AUTH_SETUP_TOKEN`.

## Upgrade

Snapshot RDS. Verify the new digest, run `./mirror-image.sh sha256:<new> "$(terraform output -raw ecr_repository_url)"`, set `image_digest`, and `terraform apply`. Read [Upgrade by digest](https://docs.backtale.app/install/upgrade.md) first if a database is already in use.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.