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.
On this page
- What the template creates
- Parameters
- Deploy
- Install the sypnia command on your machine
- Get the templates and the deploy script
- Choose the region and make the root token
- Create the database passwords
- Deploy the database stack
- Create the engine's database and role
- Write the parameters file
- Deploy the engine stack
- Load the engine's settings into your shell
- Create the tables
- Check the deployment
- Create the first project and a token
- Send from your app and see it arrive
- Point a domain at it
- Ask for a certificate in us-east-1
- Prove the domain is yours
- Give the domain to the stack
- Point the DNS record at the stack
- Check
- Change a setting
- Update the engine
- Read what changed
- Update the command and the templates
- Update the tables first
- Deploy the new template
- Check the version that answers
- Remove everything
- Note the names, then delete the engine stack
- Delete the bucket and everything in it
- Delete the database stack
- Delete the final snapshot and the passwords
- Remove what you created by hand
- Troubleshooting
- Next
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.
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 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.
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.
- The address: CloudFront, at
https://sypnia.example.com. It receives your app and you. - Function
ingest: receives/v1/ingest/*,/v1/otlp/*,/v1/sdk.jsand/v1/sdk-recorder.js. - Function
api: everything else,/v1/*,/mcpand/console. It reads the Bucket and Postgres. - The intake queue: event batches wait here.
- Function
worker: the queue wakes it with up to 10 seconds of batches, and a schedule wakes it every minute. - The Bucket (S3): replay chunks and page snapshots from
ingest; segments, per-session files and Parquet from the worker. - Postgres (RDS in the
sypnia-dbstack, or yours): problems, numbers and sessions.
Read this diagram as text
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; 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 and Data flow.
Parameters
| Parameter | Default | What it sets |
|---|---|---|
RootToken | Required | The root token, 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). |
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 has its default until you change it.
Deploy
Get the templates and the deploy script
Terminal 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.shYou should seeThe 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 andpsqlcommands you can read in it.Create the database passwords
Terminal scripts/deploy-aws.sh db-secretsYou should seeText == 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.
Deploy the database stack
Terminal scripts/deploy-aws.sh db-deployYou should seeText == 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.comAbout 10 minutes. The stack is named
sypnia-db; pass another name as an argument todb-deployanddb-init, and asDatabaseStackbelow.Create the engine's database and role
You need
psql, the PostgreSQL client (apt install postgresql-client,brew install libpq).Terminal scripts/deploy-aws.sh db-initYou should seeText == 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_engineowns the databasesypniaand nothing else. The master user is used only here. Run again, nothing changes.Write the parameters file
Terminal 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.jsonYou should seeA file~/sypnia-params.jsonwith every parameter of the table above. An emptyCodeBucketuses the published package of your region.Versionis the engine release the functions run. With your own Postgres, setDatabaseUrlin it now and skip the three database steps.Deploy the engine stack
Terminal scripts/deploy-aws.sh deploy sypnia ~/sypnia-params.jsonYou should seeText 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 upThen 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 asBaseUrl.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.
Terminal 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 seeThe address of your engine, such ashttps://d2k4x7example.cloudfront.net. Your shell now holds secrets, the root token and the database password among them: close it when you finish.Create the tables
The worker applies the migrations at its first start:
SYPNIA_AUTO_MIGRATEis 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:Terminal sypnia migrateYou should seeA list of applied migrations that ends withdatabase 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.Check the deployment
Terminal curl -i "$SYPNIA_BASE_URL/healthz" sypnia doctor --skip aiYou should seeHTTP/2 200from 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 passedsypnia doctorruns 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 byhealthzand by the next two steps.Create the first project and a token
Terminal sypnia project create --name ShopYou should seeText 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,replayTerminal sypnia token create --project shop --name "My laptop" --scopes read,replayYou should seeA line that starts withsps_. It is shown once: copy it now.Send from your app and see it arrive
Point the SDK at your engine with
endpoint, as in the quickstart:init({ project: 'spk_…', endpoint: '<your base URL>' }). Open your app, click around, then:Terminal SYPNIA_API_TOKEN=<your sps_ token> sypnia problems --environment developmentYou should seeWithin 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 at the engine, so the address in your app is the final one, and go through the 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.
Ask for a certificate in us-east-1
CloudFront only takes certificates from
us-east-1, whatever region your stack is in.Terminal aws acm request-certificate --region us-east-1 \ --domain-name sypnia.example.com --validation-method DNS \ --query CertificateArn --output textYou should seeAn address that starts witharn:aws:acm:us-east-1:. Keep it for the next steps.Prove the domain is yours
Terminal aws acm describe-certificate --region us-east-1 --certificate-arn <the ARN> \ --query "Certificate.DomainValidationOptions[0].ResourceRecord"Create the
CNAMErecord it prints at your DNS provider, then wait:Terminal aws acm wait certificate-validated --region us-east-1 --certificate-arn <the ARN>You should seeThe command returns without a message, usually within a few minutes of the record existing.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.
Terminal 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.jsonYou should seeSuccessfully created/updated stack - sypnia, after about 5 minutes.Point the DNS record at the stack
Terminal aws cloudformation describe-stacks --stack-name sypnia \ --query "Stacks[0].Outputs[?OutputKey=='DistributionDomain'].OutputValue" --output textCreate a
CNAMErecord fromsypnia.example.comto the name it prints. For a bare domain without a subdomain, use your DNS provider’s alias record.
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
AiProvidertoopenrouter,AiApiKeyto your key andAiModelto the model, then:Terminal scripts/deploy-aws.sh deploy sypnia ~/sypnia-params.jsonThen 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, underGlobals. Add the setting’sSYPNIA_…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.
Read what changed
The changelog says what each version changes and whether it asks anything of you.
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.
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.
Note the names, then delete the engine stack
Terminal 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 sypniaYou should seeThe table showsBucketName. The last command returns without a message after about 10 minutes.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.
Terminal 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-dbYou should seeThe last command returns without a message after about 10 minutes.Delete the final snapshot and the passwords
Terminal 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
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. |
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. |
| 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. |
Next
- What to close before real traffic.
- What to back up, and how long to keep data.
- What this stack costs, with the arithmetic.
- Get an e-mail when something breaks.