Run a trial Server on AWS
scripts/trial-ec2.sh makes one throwaway Linux machine on AWS for trying a Server, and deletes it
again afterwards. Use it when a trial needs real Linux, for example a Server whose Warehouse is a
DuckDB file (see Run stage and prod on a Mac
for why that can't run on a Mac).
It is a helper for trials in this repository, not a supported way to set up a Server. It is not part
of the adops package.
What up makes:
| Resource | Details |
|---|---|
| Machine | m7i-flex.large (2 cores, 8 GB), Ubuntu 24.04, named and tagged adops-trial |
| Disk | 20 GB gp3, deleted when the machine is deleted |
| Security group | adops-trial: SSH only, only from your public IP at the time you ran up |
| Key pair | adops-trial; the private key is saved at ~/.ssh/adops-trial.pem |
| Budget alert (optional) | adops-trial: emails you once usage passes $15 |
Everything except the Budget carries the tag Project=adops-trial. That tag is how down finds what
to delete.
Before you start
-
The AWS CLI and an
adops-trialprofile. The script uses the profileadops-trialand the regioneu-north-1by default. Log in first:aws login --profile adops-trialThe login is short-lived. If it expires halfway through
up, log in again and rundown(see When something goes wrong). -
The machine type must be free-tier eligible in your region.
upchecks this and stops if it isn't. It never picks a different machine type for you. -
You need at least 2 vCPUs of On-Demand quota.
upchecks this too.
To use a different profile, region or key location, set these before running the script:
| Variable | Default |
|---|---|
AWS_PROFILE |
adops-trial |
AWS_REGION |
eu-north-1 |
TRIAL_KEY_PATH |
~/.ssh/adops-trial.pem |
Step 1 — Create the machine
From the repository root:
scripts/trial-ec2.sh up
up does these in order and stops at the first problem, before anything is created:
- Checks your login, your vCPU quota and that
m7i-flex.largeis free-tier eligible. - Refuses to start if a previous
adops-trialmachine, security group, key pair or local key is still there. Rundownfirst. - Asks whether to create the $15 Budget alert, and asks for an email address if you say yes. The address goes straight to AWS and is not saved anywhere. The alert counts usage before credits, because on the Free plan credits cover the bill and an alert on the net amount would never go off.
Then it creates the key pair, the security group and the machine, waits for the machine to start, and prints the command to connect:
ssh -i ~/.ssh/adops-trial.pem ubuntu@<machine address>
Step 2 — Wait for Docker to finish installing
The machine installs Docker, the Docker Compose plugin and git on its first boot, which takes a few minutes. Connect, then wait for it:
cloud-init status --wait
When it prints status: done, docker and git are ready. If you connected before the install
finished, disconnect and connect again so that docker works without sudo.
From here, set up the Server as in Promotion. Before you delete a machine whose state you want to keep, back it up as in Back up and restore a Server.
Soak a Server under Faults
A soak runs a stage Server on the Postgres Warehouse for a day or two with two scheduled Pipelines,
and breaks it on purpose at the moments that are hardest to get right. Each break is a Fault.
After every Fault, the Invariant Checker reads the Server's stores and says whether anything was
lost, duplicated or left unreported. The harness lives in scripts/soak/ and is meant to be rerun
on every later release. It is a trial tool, not a CI job, and not part of the adops package.
| File | What it does |
|---|---|
setup.sh |
Turns the fresh machine into the soak Server: two Pipelines (shop_sync every 10 minutes, events_sync every 7), a Source writer every 30 s, an alert receiver, a resource sampler, and a deploy checkout at ~/soak/checkout. Safe to rerun. |
faults.sh |
Injects one Fault, undoes its own damage, then runs the checker. |
check_invariants.py |
The Invariant Checker. faults.sh runs it; you can run it alone with faults.sh check. |
plant_failures.sh |
Proves the checker can fail, by planting each broken Invariant in a scratch copy. |
Set up, or move to a later release
-
Build a wheel of the release to soak, on the Mac. It must carry a new version number, because
setup.shinstalls it withpipandpipskips a version it already has:uv build --wheel -
Copy
scripts/and the wheel to the machine, then runsetup.shthere:scp -i ~/.ssh/adops-trial.pem -r scripts dist/adops-<version>-py3-none-any.whl ubuntu@<machine address>: ssh -i ~/.ssh/adops-trial.pem ubuntu@<machine address> bash scripts/soak/setup.sh --wheel adops-<version>-py3-none-any.whlOn a later release, copy the new
scripts/and wheel and runsetup.shagain. It rebuilds the Server image from the new wheel and restarts the Server on it; the data, the soak state and the deploy checkout stay.
faults.sh must stay at ~/scripts/soak/faults.sh next to check_invariants.py, because the
Faults started from the Mac send the script over SSH and the machine then looks for the checker
there.
Run the Faults
Run them from the Mac and keep each one's output in soak-evidence/ (Git ignores it, because the
output names hosts and addresses). Add Host adops-trial with its HostName, User ubuntu and
IdentityFile ~/.ssh/adops-trial.pem to ~/.ssh/config, so that ssh adops-trial works:
mkdir -p soak-evidence
ssh adops-trial 'bash -s' -- source-stop < scripts/soak/faults.sh > soak-evidence/source-stop.txt 2>&1
echo "exit $?" >> soak-evidence/source-stop.txt
Two Faults run on the Mac itself, because they need a hand from outside the machine:
bash scripts/soak/faults.sh reboot-in-retry --host adops-trial > soak-evidence/reboot-in-retry.txt 2>&1
Don't pipe the output through tee without set -o pipefail: the exit code is the result.
| Exit code | Meaning |
|---|---|
| 0 | Every Invariant passed. |
| 1 | An Invariant failed (named on a FAIL line), or the Fault's own check failed (a FAULT FAIL: line). |
| 2 | Setup error: a store could not be reached, or a bad argument. Nothing was judged. |
| 3 | No Invariant failed, but one was not checked (a DuckDB Warehouse stayed locked). |
| 4 | The Fault could not reach its moment within 15 minutes, undid what it had changed, and injected nothing else. Run it again. |
In this order, on the Postgres Server:
| Fault | What it does | Pass |
|---|---|---|
source-stop |
Holds the events_sync Pipeline Lock until a scheduled run waits for it, stops the shop Source, lets the run in, waits until it is in its 300 s retry wait, then starts the Source again. A shop_sync run that reaches its Reverse Sync while shop is stopped fails, because shop is also its Target; that failure and its one alert are expected. |
The retry succeeds; the checker passes. |
kill-worker --stretch 300000 |
Adds 300,000 orders so the Sync takes a while, then kill -9s the shop_sync run worker while its dlt package is still pending. It finds the worker from the run's Started process for run (pid: N) event, checks in pg_stat_activity (application_name adops-warehouse-lock) that the run holds its Pipeline Lock and with ss -tnp that the process is connected to the Warehouse. It refuses to kill if no package is pending. |
The next run finishes the pending package; the failed run has exactly one alert. |
backfill-overlap |
Runs adops backfill shop_sync orders while a scheduled run holds the Pipeline Lock, then lets a schedule tick come while a backfill holds it. A backfill is itself a run of the Pipeline, so that tick is skipped, not queued. It holds the dbt Lock to keep each holder inside the lock long enough. |
The first backfill waits and passes; the tick during the second is skipped and no scheduled run starts; the second backfill passes. |
backfill-kill |
Adds 300,000 orders, starts a backfill and docker kills it as soon as its cursor rewind is written. |
The cursor is not left below where it was before the backfill, and the killed backfill's Dagster run is not left STARTED. A STARTED run makes the Schedule skip the Pipeline until dagster_daemon restarts, so the Fault restarts it once no other run is going (its server-recover marks the run failed and sends one alert). |
overlap-old-release |
Holds the dbt Lock so a scheduled shop_sync run of the old release waits at its Transform, makes 3 releases from the deploy checkout and replays the deploy (adops server-release, the reload, adops run --all --changed). |
The old run's release folder is kept while it runs (3 newer releases would otherwise remove it), and the saved Step Fingerprints match the new release. |
overlap-queued-run |
Holds the Pipeline Lock so a scheduled run of the old code waits, replays the deploy, then lets the old run go first and the deploy's run after it. | The saved Step Fingerprints match the new release, and the next tick carries the new adops/release tag. |
reboot-in-retry (Mac) |
Puts an events_sync run in its retry wait with the Source stopped, reboots the machine, waits one schedule tick, then restarts the Server. |
See the reboot caution below. |
backup-under-load |
Dumps the Warehouse and the Dagster database while runs go on (it skips the "stop the Server" step of Back up and restore a Server on purpose), restores them into a separate compose project adops-soak-restore on ports +100, compares, and removes the copy. Needs 2 GB free. |
Every restored table and Load Record is also in the live Warehouse; the live Warehouse lost no rows; only the live compose project is left. |
disk-full (Mac) |
Fills the root disk with /var/tmp/adops-soak-fill for 11 minutes, so a scheduled tick hits a full disk, then deletes it. |
The disk has space again and the next tick succeeds. |
Then switch stage to a DuckDB Warehouse (the commented warehouse: block in ~/soak/server/adops.yaml)
and run duckdb-deploy-while-running --stretch 2000000. It adds 2,000,000 customers so a run takes
minutes, replays the deploy during that run, and records whether the deploy's run waited for the
DuckDB lock or refused. It removes the added customers afterwards.
Options: --pipeline <name> (default shop_sync, or events_sync for source-stop and
reboot-in-retry), --table <incremental table> (default orders), --stretch <rows>,
--from <date> (backfill start, default today), --releases <n>, --hold <minutes>.
scripts/soak/faults.sh --help lists them all.
Cautions:
- Every Fault undoes its own damage, even when stopped with Ctrl-C: it starts the Source again,
ends the database sessions holding its locks, removes its backfill container and the restored
copy, and deletes the disk-fill file. It does this too when the SSH connection drops: the cleanup
then writes what it did to
/var/lib/adops-soak/faults-cleanup.loginstead. A lock a Fault holds ends by itself 35 minutes later even if the script is killed outright. If a Mac-side Fault dies with its SSH connection, check by hand:ls /var/tmp/adops-soak-fillshould find nothing, anddocker compose lsshould list onlyserver. - Reboot. The 72-hour shutdown is set at first boot only, so
reboot-in-retrysets it again for the hours left since/var/lib/adops-soak/first-boot, never a fresh 72 hours. Its output showsshutdown --show. If the 72 hours have already passed, it shuts the machine down. The Fault waits one tick first and prints aFINDING:line saying whether the Server came back by itself (a Server made with adops older than 0.4.1 has no restart policy), before it starts it. - Disk full. Run it late, after
backup-under-load. Before filling the disk it opens a second SSH session and keeps it open, because a new SSH login can fail on a full disk; the fill file is deleted from that session. If everything fails,sudo rm -f /var/tmp/adops-soak-fillon the machine. - The soak state. The checker keeps each cursor's highest value and every backfill window in
/var/lib/adops-soak/soak-state.json, so it can tell a cursor that moved back from an allowed backfill rewind. Keep that file for the whole soak. - Releases and rows add up. Each overlap Fault commits to
~/soak/checkoutand adds release folders, and--stretchadds rows to theshopSource. Both are expected. Watch disk withbash ~/soak/bin/trial-sample.sh trend /var/lib/adops-soak/sample.csv.
To rehearse against a local stage Server, set SOAK_SERVER_DIR, SOAK_CHECKOUT, SOAK_STATE_DIR,
SOAK_HOME and SOAK_PYTHON (a Python that has adops installed) and run faults.sh there.
kill-worker, reboot-in-retry and disk-full need the Linux machine.
Step 3 — Delete everything
scripts/trial-ec2.sh down
down deletes every adops-trial resource, found by tag or by name:
- Terminates the machine and waits until it is gone.
- Deletes any leftover
adops-trialdisks. - Deletes the
adops-trialsecurity group. If AWS still says the group is in use, it retries for up to 2 minutes. - Deletes the
adops-trialkey pair and the local key file. - Deletes the
adops-trialBudget alert, if there is one.
Then it checks again. It ends with No adops-trial resources are left., or it lists what is still
there under Still present: and exits with an error. down is safe to run as often as you like.
With nothing to delete, it finishes straight away.
Always run down when the trial is over. The machine stops itself after 72 hours, but a stopped
machine's disk is still billed until it is deleted.
Cost guards
- The machine shuts itself down 72 hours after it first starts. This is set once at first boot. If you start the machine again yourself afterwards, it does not shut itself down a second time.
- The optional Budget alert emails you once usage passes $15. It only warns you. It does not stop anything.
downdeletes everything the script made. Nothing is left behind to bill you.
When something goes wrong
| What you see | What to do |
|---|---|
AWS credentials ... are missing or expired |
Run aws login --profile adops-trial, then run the command again. |
up stopped halfway (login expired, network error) |
Log in again, run down to clear what was made, then run up again. |
up says something from a previous run still exists |
Run down, then up. |
ssh times out |
Your public IP has probably changed since up, for example on a different network. SSH is only open to the IP you had then. Run down and up again from your current network. |
down ends with Still present: |
Run down again. If something is still left, delete it in the AWS console: EC2 lists the machine, disks, security group and key pair, and Billing lists the Budget. |
... security group is still in use after 2 minutes |
AWS is still releasing the network attachment of the deleted machine. Wait a minute and run down again. |