# Deploy on AWS

> Deploy the Sypnia engine on your own AWS account with two CloudFormation stacks, its database and the engine, check it, create the first project, point a domain at it, update it, and remove it.

Applies to: the Sypnia engine (open source, self-hosted).  
Source: https://telemetry.docs.sypnia.com/self-hosting/deploy-aws/

For agents: How to deploy the self-hosted Sypnia engine on AWS: the database stack sypnia-db.yaml (one RDS for PostgreSQL instance, passwords as SSM SecureStrings) and the engine stack sypnia-aws.yaml (three Lambda functions, a queue, a schedule, an S3 bucket, a CloudFront address), deployed with scripts/deploy-aws.sh; parameters, step-by-step commands with expected results, custom domain, updates, changing settings, and removal.

**\[Engine]** This page is for whoever deploys the open-source engine on their own AWS account. It does not apply to Sypnia Cloud, which is this same shape run by us. If you do not use AWS, follow [Deploy with Docker](https://telemetry.docs.sypnia.com/self-hosting/deploy-docker).

**At the end you will have:** the engine answering at an HTTPS address of your AWS account, its bucket, its database in a stack of its own, a first project with an ingest key and an API token, and `sypnia doctor` passing.

**You need:** an AWS account and the [AWS CLI](https://docs.aws.amazon.com/cli/) version 2, signed in as someone who can create functions, roles, a bucket, a queue, a CloudFront distribution, an RDS instance and SSM parameters; `git`, `jq`, `openssl` and `psql`; about 40 minutes, most of it waiting.

> **Note: Times**
>
> Times on this page are estimates.

## What the template creates

Two CloudFormation templates, two stacks. `sypnia-db.yaml` creates the database, in a stack of its own named `sypnia-db`, so you can delete and create the engine stack again while the data stays. `sypnia-aws.yaml` creates everything else in the stack `sypnia`. The same `sypnia` binary runs as three functions; each one is the engine with one role. `scripts/deploy-aws.sh` deploys both, in order.

**Figure**: The stack the template creates. Three functions are the same binary with three roles.

1. The address: CloudFront, at `https://sypnia.example.com`. It receives your app and you.
2. Function `ingest`: receives `/v1/ingest/*`, `/v1/otlp/*`, `/v1/sdk.js` and `/v1/sdk-recorder.js`.
3. Function `api`: everything else, `/v1/*`, `/mcp` and `/console`. It reads the Bucket and Postgres.
4. The intake queue: event batches wait here.
5. Function `worker`: the queue wakes it with up to 10 seconds of batches, and a schedule wakes it every minute.
6. The Bucket (S3): replay chunks and page snapshots from `ingest`; segments, per-session files and Parquet from the worker.
7. Postgres (RDS in the `sypnia-db` stack, or yours): problems, numbers and sessions.

Inside the frame «Your AWS account · stack: sypnia». The lit path is the one an event takes: Your app (SDK) → Address → `ingest` → Queue → `worker`. You, your coding agent and your CI reach `api` through the same address. Two dashed arrows leave the frame from the worker: your webhook, and your AI provider, which is off until you set a key.

| # | Resource                                                            | What it does                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Template default                                                                                                                  |
| - | ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| 1 | A CloudFront distribution                                           | The engine's one HTTPS address. Sends `/v1/ingest/*`, `/v1/otlp/*` and the SDK's two script files (`/v1/sdk.js`, `/v1/sdk-recorder.js`) to the ingest function and everything else to the API function. Takes your own domain if you give one.                                                                                                                                                                                                                                                                                                  | No caching, except those two files                                                                                                |
| 2 | Function `sypnia-ingest` (the stack's name, then `-ingest`)         | `SYPNIA_ROLE=ingest`. Checks each batch and puts it in the queue; writes replay chunks and page snapshots to the bucket.                                                                                                                                                                                                                                                                                                                                                                                                                        | 256 MB, 10 s, at most 40 copies at once                                                                                           |
| 3 | Function `sypnia-api`                                               | `SYPNIA_ROLE=api`. The API, the MCP server and the Console. The MCP server answers each POST with plain JSON and never holds a stream open, so CloudFront and the function URL carry it like any API call.                                                                                                                                                                                                                                                                                                                                      | 512 MB, 30 s, at most 20 copies                                                                                                   |
| 4 | A queue, and a second one for messages that failed five times       | Holds batches for up to 4 days until the worker writes them. It is the buffer a function cannot keep in memory.                                                                                                                                                                                                                                                                                                                                                                                                                                 | Standard queue                                                                                                                    |
| 5 | Function `sypnia-worker`, and a schedule that wakes it every minute | `SYPNIA_ROLE=worker`. Writes segments, finds problems, counts, runs uptime checks, the agent, alerts, webhooks and retention. Woken by the queue, and by the schedule when there is no traffic.                                                                                                                                                                                                                                                                                                                                                 | 1,024 MB, 15 min, at most 3 copies: the queue uses up to 2, so the minute schedule always finds one                               |
| 6 | An S3 bucket                                                        | Raw events, replays, snapshots, source maps. Private, encrypted, public access blocked, a rule that lets your address read replays from a browser, and one lifecycle rule that removes unfinished uploads after 7 days.                                                                                                                                                                                                                                                                                                                         | Kept when the stack is deleted                                                                                                    |
| 7 | An RDS Postgres, **in the stack `sypnia-db`**                       | The database, from `sypnia-db.yaml`. Postgres 16, one zone, 20 GB of gp3 that grows by itself up to 100 GB (enough for the small size of [Scaling and cost](https://telemetry.docs.sypnia.com/self-hosting/scaling-and-cost); give it more memory before the medium one), encrypted, TLS forced, daily backups kept 7 days, deletion protection on. Its master password and the engine's are SSM SecureStrings. The engine has its own database (`sypnia`) and role (`sypnia_engine`); other applications can have theirs on the same instance. | `db.t4g.micro`; when it runs short, resize it to `db.t4g.small`, with no migration. A snapshot is taken when its stack is deleted |
|   | Roles, and a log group per function                                 | Each function may touch only this stack's bucket, queues and log group: `ingest` may send to the queue and put objects, `api` may read objects and sign links, `worker` may read and write the bucket. Logs are kept 30 days.                                                                                                                                                                                                                                                                                                                   |                                                                                                                                   |
|   | Three alarms                                                        | `DeadLetterNotEmpty`: a message landed in the second queue. `IntakeBacklog`: the oldest message of the queue has waited more than 2 minutes, for 3 minutes. `WorkerFailing`: the worker keeps failing. They show in CloudWatch; `AlarmEmail` or `AlarmTopicArn` sends them to you.                                                                                                                                                                                                                                                              |                                                                                                                                   |

You do not operate the queue or the schedule: the template creates them and AWS runs them. Why functions need a queue, what each function is woken by, and what it changes in the timing, is in [Deployment shapes](https://telemetry.docs.sypnia.com/architecture/deployment-shapes) and [Data flow](https://telemetry.docs.sypnia.com/architecture/data-flow).

> **Warning: The database is reachable from the internet**
>
> The functions run outside a private network, so that they can reach your webhook, your AI provider and the addresses of your uptime checks without a NAT gateway, which alone costs about USD 33 a month. Their addresses are not fixed, so the instance is public and its port 5432 is open to any address. What protects it: TLS forced (`rds.force_ssl`), one generated 48-character password for each application, and a master password used only by `db-init` to create databases and roles. IAM authentication is switched on in the instance and not used yet: using it for the engine's role, which would take the password out of the functions' configuration, is the next step. The stronger shape is the functions in a private network with RDS Proxy and IAM authentication, the instance's security group closed to the world, and a NAT gateway or VPC endpoints for SQS, S3 and SSM. If the public instance is not acceptable to you, bring a Postgres with the network rules you want (`DatabaseUrl`), or use the [Docker shape](https://telemetry.docs.sypnia.com/self-hosting/deploy-docker) inside your own network.

## Parameters

| Parameter                               | Default                    | What it sets                                                                                                                                                                                                       |
| --------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `RootToken`                             | Required                   | The [root token](https://telemetry.docs.sypnia.com/concepts/projects-keys-and-tokens), `SYPNIA_ROOT_TOKEN`. At least 32 characters.                                                                                |
| `DatabaseStack`                         | `sypnia-db`                | The database stack whose instance the engine uses: its export `<stack>-Host` names the host. Ignored when `DatabaseUrl` is set.                                                                                    |
| `DatabaseName`, `DatabaseUser`          | `sypnia`, `sypnia_engine`  | The engine's database in that instance and the role that owns it, both created by `scripts/deploy-aws.sh db-init`.                                                                                                 |
| `DatabasePassword`                      | Empty                      | The role's password. Never write it: `scripts/deploy-aws.sh deploy` reads it from the SSM SecureString `/sypnia/engine/db-password` and passes it here. It is never printed. Required unless `DatabaseUrl` is set. |
| `DatabaseUrl`                           | Empty                      | Instead of the shared instance, your own Postgres 15 or later, as `SYPNIA_DATABASE_URL`: a direct or session-mode connection. End it with `?sslmode=require`.                                                      |
| `DomainName`                            | Empty                      | Your own domain for the engine, such as `sypnia.example.com`. Empty uses the address CloudFront gives the stack.                                                                                                   |
| `BaseUrl`                               | Empty                      | Only without `DomainName`: the CloudFront address, `https://<DistributionDomain>`, which exists only after the first deploy. `scripts/deploy-aws.sh deploy` sets it in a second pass.                              |
| `CertificateArn`                        | Empty                      | The certificate for `DomainName`, from AWS Certificate Manager in `us-east-1`. Required with `DomainName`.                                                                                                         |
| `AiProvider`, `AiApiKey`, `AiModel`     | `none`, empty, empty       | `SYPNIA_AI_PROVIDER`, `SYPNIA_AI_API_KEY`, `SYPNIA_AI_MODEL`. The agent is off while the provider is `none`.                                                                                                       |
| `AlertWebhookUrl`, `AlertWebhookSecret` | Empty                      | `SYPNIA_ALERT_WEBHOOK_URL`, `SYPNIA_ALERT_WEBHOOK_SECRET`. Empty sends nothing; alerts are still recorded.                                                                                                         |
| `AlarmEmail`                            | Empty                      | An e-mail address for the three alarms. The template creates a topic and subscribes it; confirm the e-mail AWS sends. Ignored when `AlarmTopicArn` is set.                                                         |
| `AlarmTopicArn`                         | Empty                      | An SNS topic of yours for the three alarms. With both empty, the alarms show in CloudWatch only.                                                                                                                   |
| `Version`                               | The template's own version | Which release of the engine the functions run. The package is read from `s3://<CodeBucket>/sypnia/<Version>/sypnia-lambda-arm64.zip`.                                                                              |
| `CodeBucket`                            | `sypnia-releases-<region>` | The bucket the function package is read from. Change it only if your region has none (see [Troubleshooting](#troubleshooting)).                                                                                    |

The template sets these settings itself, and you should not change them: `SYPNIA_BASE_URL`, `SYPNIA_ROLE`, `SYPNIA_STORAGE_BUCKET`, `SYPNIA_STORAGE_REGION`, `SYPNIA_INTAKE_QUEUE_URL`, `SYPNIA_INTAKE_DEAD_LETTER_QUEUE_URL`, `SYPNIA_TRUSTED_PROXY_HOPS` and `SYPNIA_DATABASE_MAX_CONNECTIONS`. The worker also gets `SYPNIA_AUTO_MIGRATE=true`, so it applies new migrations at its first start. Every other setting of the [configuration reference](https://telemetry.docs.sypnia.com/self-hosting/configuration) has its default until you [change it](#change-a-setting).

## Deploy

### 1. Install the sypnia command on your machine

You will use it to check the deployment and create the first project.

```bash
curl -fsSL https://sypnia.com/install.sh | sh
sypnia version
```

**You should see:**

```text
sypnia 1.0.0 (a1c9e3f, 2026-03-01) schema 12
```

### 2. Get the templates and the deploy script

```bash
git clone --depth 1 https://github.com/sespinosav/sypnia-telemetry.git
cd sypnia
ls deploy/sypnia-db.yaml deploy/sypnia-aws.yaml deploy/sypnia-aws.params.example.json scripts/deploy-aws.sh
```

**You should see:**The four files. Read the two templates if you want to know exactly what will be created: they are the whole deployment. The script only runs AWS CLI and `psql` commands you can read in it.

### 3. Choose the region and make the root token

```bash
export AWS_REGION=us-east-1
openssl rand -hex 32 > ~/sypnia-root-token.txt
chmod 600 ~/sypnia-root-token.txt
```

**You should see:**A file with 64 characters. Keep it somewhere safe, such as your password manager: it can do everything on every project.

### 4. Create the database passwords

```bash
scripts/deploy-aws.sh db-secrets
```

**You should see:**

```text
== db-secrets: /sypnia/db/master-password created (version 1)
== db-secrets: /sypnia/engine/db-password created (version 1)
```

Two SSM SecureStrings of 48 generated characters: the instance's master password and the engine's own. They are written through a file only you can read and never printed. Run again, the command keeps what exists.

### 5. Deploy the database stack

```bash
scripts/deploy-aws.sh db-deploy
```

**You should see:**

```text
== db-deploy: sypnia-db (RDS for PostgreSQL 16, db.t4g.micro, deletion protection on)
Successfully created/updated stack - sypnia-db
== db-deploy: host sypnia-db-instance-1a2b3c.c9xexample.us-east-1.rds.amazonaws.com
```

About 10 minutes. The stack is named `sypnia-db`; pass another name as an argument to `db-deploy` and `db-init`, and as `DatabaseStack` below.

### 6. Create the engine's database and role

You need `psql`, the PostgreSQL client (`apt install postgresql-client`, `brew install libpq`).

```bash
scripts/deploy-aws.sh db-init
```

**You should see:**

```text
== db-init: role sypnia_engine and database sypnia on sypnia-db-instance-1a2b3c.c9xexample.us-east-1.rds.amazonaws.com
== db-init: done; the engine's worker applies its migrations at its first start (SYPNIA_AUTO_MIGRATE)
```

The role `sypnia_engine` owns the database `sypnia` and nothing else. The master user is used only here. Run again, nothing changes.

### 7. Write the parameters file

```bash
jq --arg token "$(cat ~/sypnia-root-token.txt)" \
  '.Parameters.RootToken = $token | .Parameters.CodeBucket = ""' \
  deploy/sypnia-aws.params.example.json > ~/sypnia-params.json
chmod 600 ~/sypnia-params.json
```

**You should see:**A file `~/sypnia-params.json` with every parameter of the table above. An empty `CodeBucket` uses the published package of your region. `Version` is the engine release the functions run. With your own Postgres, set `DatabaseUrl` in it now and skip the three database steps.

### 8. Deploy the engine stack

```bash
scripts/deploy-aws.sh deploy sypnia ~/sypnia-params.json
```

**You should see:**

```text
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - sypnia
== deploy: giving the functions their address, https://d2k4x7example.cloudfront.net
Successfully created/updated stack - sypnia
== deploy: sypnia is up
```

Then a table of the stack's outputs. About 10 minutes, most of it the CloudFront address. The script reads the engine's database password from SSM and hands it to the template's `DatabasePassword`, so it is in no file and on no screen. Without a domain it deploys twice: the CloudFront address exists only after the first deploy, and the second gives it to the functions as `BaseUrl`.

### 9. Load the engine's settings into your shell

The functions hold the engine's settings as environment variables. Read them from the worker, so the commands you run next use exactly the same database and bucket.

```bash
eval "$(aws lambda get-function-configuration --function-name sypnia-worker \
  --query 'Environment.Variables' --output json \
  | jq -r 'to_entries[] | select(.key | startswith("SYPNIA_")) | "export \(.key)=\(.value | @sh)"')"
echo "$SYPNIA_BASE_URL"
```

**You should see:**The address of your engine, such as `https://d2k4x7example.cloudfront.net`. Your shell now holds secrets, the root token and the database password among them: close it when you finish.

### 10. Create the tables

The worker applies the migrations at its first start: `SYPNIA_AUTO_MIGRATE` is on for the worker only, and ingest and the API never change the schema. The minute schedule starts it within a minute of the deploy. To apply them yourself, now:

```bash
sypnia migrate
```

**You should see:**A list of applied migrations that ends with `database is up to date`, or only that line when the worker was first. Until the tables exist, the functions refuse to start and the address answers with an error.

### 11. Check the deployment

```bash
curl -i "$SYPNIA_BASE_URL/healthz"
sypnia doctor --skip ai
```

**You should see:**

`HTTP/2 200` from the first command. From the second:

```text
config    ok    14 settings read, 0 unknown
database  ok    postgres 16.12, schema 12 (up to date), 41 ms
storage   ok    s3://sypnia-bucket-1a2b3c4d5e6f: put, get, delete, presign
address   ok    https://d2k4x7example.cloudfront.net/healthz answered 200
pipeline  ok    last pass 14 s ago, lag 0 s, 0 quarantined, 0 failed hours, 0 dead jobs
queue     ok    intake 0 waiting, dead-letter 0
webhook   skip  SYPNIA_ALERT_WEBHOOK_URL is not set (alerts are recorded only)
clock     ok    0.3 s from the database's clock
all checks passed
```

`sypnia doctor` runs on your machine with your own AWS sign-in. It proves the settings, the database, the bucket, that processing is up to date and that the dead-letter queue is empty. That the functions themselves can reach them is proved by `healthz` and by the next two steps.

### 12. Create the first project and a token

```bash
sypnia project create --name Shop
```

**You should see:**

```text
project     shop (prj_5k2m9x4q7w1z)
ingest key  spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e

Put the ingest key in your app. It is public: it can only send.
Next: sypnia token create --project shop --name "My laptop" --scopes read,replay
```

```bash
sypnia token create --project shop --name "My laptop" --scopes read,replay
```

**You should see:**A line that starts with `sps_`. It is shown once: copy it now.

### 13. Send from your app and see it arrive

Point the SDK at your engine with `endpoint`, as in the [quickstart](https://telemetry.docs.sypnia.com/start/quickstart-self-host): `init({ project: 'spk_…', endpoint: '<your base URL>' })`. Open your app, click around, then:

```bash
SYPNIA_API_TOKEN=<your sps_ token> sypnia problems --environment development
```

**You should see:**Within 2 minutes of a first error, one problem. Sessions and numbers follow within 10 minutes. The Console is at `<your base URL>/console`.

Before real traffic, [point your domain](#point-a-domain-at-it) at the engine, so the address in your app is the final one, and go through the [security checklist](https://telemetry.docs.sypnia.com/self-hosting/security-checklist).

## Point a domain at it

**At the end you will have:** the engine at `https://sypnia.example.com`. Do this before you ship the SDK in your app. The CloudFront address keeps working afterwards, so nothing that already sends to it breaks.

### 1. Ask for a certificate in us-east-1

CloudFront only takes certificates from `us-east-1`, whatever region your stack is in.

```bash
aws acm request-certificate --region us-east-1 \
  --domain-name sypnia.example.com --validation-method DNS \
  --query CertificateArn --output text
```

**You should see:**An address that starts with `arn:aws:acm:us-east-1:`. Keep it for the next steps.

### 2. Prove the domain is yours

```bash
aws acm describe-certificate --region us-east-1 --certificate-arn <the ARN> \
  --query "Certificate.DomainValidationOptions[0].ResourceRecord"
```

Create the `CNAME` record it prints at your DNS provider, then wait:

```bash
aws acm wait certificate-validated --region us-east-1 --certificate-arn <the ARN>
```

**You should see:**The command returns without a message, usually within a few minutes of the record existing.

### 3. Give the domain to the stack

Set the two parameters in your parameters file, then deploy it. The file is the truth for every parameter it names.

```bash
jq --arg arn '<the ARN>' \
  '.Parameters.DomainName = "sypnia.example.com" | .Parameters.CertificateArn = $arn' \
  ~/sypnia-params.json > ~/sypnia-params.new && mv ~/sypnia-params.new ~/sypnia-params.json
scripts/deploy-aws.sh deploy sypnia ~/sypnia-params.json
```

**You should see:**`Successfully created/updated stack - sypnia`, after about 5 minutes.

### 4. Point the DNS record at the stack

```bash
aws cloudformation describe-stacks --stack-name sypnia \
  --query "Stacks[0].Outputs[?OutputKey=='DistributionDomain'].OutputValue" --output text
```

Create a `CNAME` record from `sypnia.example.com` to the name it prints. For a bare domain without a subdomain, use your DNS provider's alias record.

### 5. Check

```bash
curl -i https://sypnia.example.com/healthz
```

**You should see:**`HTTP/2 200`. `SYPNIA_BASE_URL` is now `https://sypnia.example.com`: links in alerts and prompts use it, and so does the Console. Load the settings into your shell again before the next `sypnia` command.

## Change a setting

Settings are read when a function starts, and a deploy restarts the functions.

- **A setting that has a parameter:** change it in your parameters file and deploy again. For example, to connect a model, set `AiProvider` to `openrouter`, `AiApiKey` to your key and `AiModel` to the model, then:

  ```bash
  scripts/deploy-aws.sh deploy sypnia ~/sypnia-params.json
  ```

  Then load the settings again and run `sypnia doctor --only ai`.

- **Any other setting:** the three functions share one list of environment variables near the top of `deploy/sypnia-aws.yaml`, under `Globals`. Add the setting's `SYPNIA_…` line there and deploy. Lambda keeps a function's environment under 4 KB; the list is about 1 KB with every optional value set. Keep your change when you pull a newer template.

## Update the engine

**At the end you will have:** the three functions on the new version, without stopping ingest. Migrations only add, so the old functions keep working against the new tables while the stack updates.

### 1. Read what changed

The [changelog](https://telemetry.docs.sypnia.com/reference/changelog) says what each version changes and whether it asks anything of you.

### 2. Update the command and the templates

In the folder you cloned:

```bash
curl -fsSL https://sypnia.com/install.sh | sh
git pull
sypnia version
```

**You should see:**The new version and the schema it needs, such as `sypnia 1.1.0 (…) schema 13`. Set `Version` to it in your parameters file.

### 3. Update the tables first

With the settings loaded in your shell:

```bash
sypnia migrate
```

**You should see:**`database is up to date`. Without this step the new worker applies them at its first start; running it first means no function ever starts against an older schema.

### 4. Deploy the new template

```bash
scripts/deploy-aws.sh deploy sypnia ~/sypnia-params.json
```

**You should see:**`== deploy: sypnia is up`. The database stack is not touched.

### 5. Check the version that answers

```bash
curl -s -o /dev/null -D - "$SYPNIA_BASE_URL/v1/whoami" \
  -H "Authorization: Bearer $SYPNIA_ROOT_TOKEN" | grep -i sypnia-version
```

**You should see:**`sypnia-version: 1.1.0`

To go back, deploy the previous template again. The database needs nothing: an older engine works against a newer schema. More on this in [Upgrades, backups, retention](https://telemetry.docs.sypnia.com/self-hosting/upgrades-backups-retention).

## Remove everything

Deleting the engine stack removes the functions, the queue, the schedule, the address, the roles and the logs. It deliberately leaves your data: the bucket is kept, and the database is in its own stack, which stays until you delete it.

### 1. Note the names, then delete the engine stack

```bash
aws cloudformation describe-stacks --stack-name sypnia --query "Stacks[0].Outputs" --output table
aws cloudformation delete-stack --stack-name sypnia
aws cloudformation wait stack-delete-complete --stack-name sypnia
```

**You should see:**The table shows `BucketName`. The last command returns without a message after about 10 minutes.

### 2. Delete the bucket and everything in it

This cannot be undone.

```bash
aws s3 rb s3://<BucketName> --force
```

**You should see:**A line `remove_bucket: <BucketName>` at the end.

### 3. Delete the database stack

Only if nothing else uses the instance: other applications may have their own database in it. Deletion protection is on, so switch it off first. The stack takes a final snapshot when it is deleted.

```bash
DB_INSTANCE=$(aws cloudformation describe-stacks --stack-name sypnia-db \
  --query "Stacks[0].Outputs[?OutputKey=='InstanceId'].OutputValue" --output text)
aws rds modify-db-instance --db-instance-identifier "$DB_INSTANCE" \
  --no-deletion-protection --apply-immediately
aws cloudformation delete-stack --stack-name sypnia-db
aws cloudformation wait stack-delete-complete --stack-name sypnia-db
```

**You should see:**The last command returns without a message after about 10 minutes.

### 4. Delete the final snapshot and the passwords

```bash
aws rds describe-db-snapshots --db-instance-identifier "$DB_INSTANCE" --snapshot-type manual \
  --query "DBSnapshots[].DBSnapshotIdentifier" --output text
aws rds delete-db-snapshot --db-snapshot-identifier <the name printed>
aws ssm delete-parameters --names /sypnia/db/master-password /sypnia/engine/db-password
```

### 5. Remove what you created by hand

The DNS records, the certificate (`aws acm delete-certificate`), the root token file and the parameters file.

After this, nothing of Sypnia is left in the account and nothing is billed.

## Troubleshooting

| What you see                                                                                                        | Why                                                                                                                                                     | What to do                                                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Requires capabilities : [CAPABILITY_AUTO_EXPAND]`                                                                  | The template uses a CloudFormation transform.                                                                                                           | Pass both capabilities, as in the commands above.                                                                                                                                                                     |
| The stack fails on a function with «S3 bucket does not exist» or «Access Denied»                                    | The function package is not published in your region.                                                                                                   | Download `sypnia-lambda-arm64.zip` from the same release, upload it to a bucket of yours in that region under `sypnia/<Version>/sypnia-lambda-arm64.zip`, and set `CodeBucket` to your bucket in the parameters file. |
| The stack fails with «DatabasePassword (from SSM /sypnia/engine/db-password) is required unless DatabaseUrl is set» | The stack was deployed without the script, or before `db-secrets`.                                                                                      | Run `scripts/deploy-aws.sh db-secrets`, then deploy with `scripts/deploy-aws.sh deploy`.                                                                                                                              |
| `db-init` fails with `password authentication failed` or `no pg_hba.conf entry`                                     | The SSM password and the instance's differ, or the connection is not TLS.                                                                               | Check that `db-deploy` ran after `db-secrets`. `db-init` always connects with `sslmode=require`.                                                                                                                      |
| The stack fails with «The specified SSL certificate doesn't exist, isn't in us-east-1 region»                       | The certificate was requested in another region.                                                                                                        | Request it again with `--region us-east-1`.                                                                                                                                                                           |
| `healthz` answers `502` or `503` right after the first deploy                                                       | The tables do not exist yet: the worker has not had its first start. The engine refuses to start against a schema older than itself.                    | Wait a minute, or run `sypnia migrate`. To see the reason: `aws logs tail /aws/lambda/sypnia-api --since 10m`.                                                                                                        |
| `sypnia doctor` says `database FAIL` from your machine, with your own Postgres                                      | Your database does not accept connections from the internet. The functions are outside your network, as your machine is.                                | Allow the connection with TLS, or use a database the functions can reach.                                                                                                                                             |
| `sypnia doctor` passes and no problem ever appears                                                                  | The worker is not running.                                                                                                                              | `aws logs tail /aws/lambda/sypnia-worker --since 10m`. A line that names a missing setting, or a database error, says what to fix.                                                                                    |
| The API answers `503` with `Retry-After` under load                                                                 | The database has no free connection.                                                                                                                    | See [Scaling and cost](https://telemetry.docs.sypnia.com/self-hosting/scaling-and-cost#database-connections).                                                                                                         |
| Browsers get `403 origin_not_allowed`                                                                               | The project lists allowed origins, and your app's is not among them.                                                                                    | Add it with `PATCH /v1/projects/{project_ref}`. See the [API reference](https://telemetry.docs.sypnia.com/api/projects-keys-and-tokens).                                                                              |
| Events arrive and the Console does not play a replay                                                                | The replay is read by your browser straight from the bucket, through a short-lived link. A proxy or an extension that blocks `amazonaws.com` breaks it. | Try another browser profile. See [The Console](https://telemetry.docs.sypnia.com/self-hosting/console#when-something-does-not-show).                                                                                  |

## Next
