mysql client, write some rows, stop the sandbox, and read them back.
MySQL doesn’t need to know anything about Archil. It reads and writes files in its data directory as usual, and Archil keeps them durable in object storage, so the database outlives any one sandbox.
Prerequisites
Export your Archil API key and a region where sandboxes are available (aws-us-east-1, aws-us-west-2, or aws-eu-west-1):
mysql client and socat, which carries the connection over TLS to the sandbox:
root user and to an app user, and the mysql client reads it later:
Write the setup script
This script runs inside the sandbox. The Archil disk is mounted by root, and MySQL runs as themysql user, so the script hands the data directory over first. On an empty disk it then initializes MySQL with an init file that sets the root password, creates an app database, and creates an app user that can connect from anywhere with the password. Finally, it registers MySQL as a service, which restarts if it crashes and starts again whenever the sandbox boots. --require-secure-transport makes MySQL reject network connections that don’t use TLS; the server generates its own certificate during initialization.
setup.sh
mysql-data disk, and it just starts the server on the data that’s already there.
Start the database
The next script creates a disk, creates a sandbox from the officialmysql:8.4 image with the disk mounted at /mnt/archil, uploads setup.sh, and runs it with your password. Then it exposes port 3306 publicly and prints the hostname.
Connect from your machine
Archil serves public ports over TLS on port 443 with a publicly trusted certificate, and forwards the decrypted TCP stream to the sandbox. Themysql client can’t open that kind of TLS connection on its own, so start a local socat
tunnel that listens on port 13306, wraps each connection in TLS, and verifies Archil’s certificate. Use the hostname
that create printed:
socat may print a warning that it doesn’t check certificate revocation lists; the tunnel still verifies the
certificate. Now connect through the tunnel as the app user. Use 127.0.0.1 rather than localhost, which the
mysql client treats as a local socket. --ssl-mode=REQUIRED makes MySQL encrypt the stream inside the tunnel, too,
so it stays encrypted all the way to the server:
Stop it and let a connection wake it
A stopped sandbox doesn’t use compute, and a connection to its public port starts it again. Stop the sandbox:SIGTERM to MySQL, which shuts down cleanly. Query the table again through the same tunnel:
mysql service before answering, in a few seconds. The rows
were on the Archil disk the whole time. With MySQL’s default settings, InnoDB flushes its redo log to the Archil disk
on every commit, so a committed transaction survives a crash, too.
Clean up
Stop the tunnel, then stop and delete the sandbox and delete the disk:Next steps
Persistent sandboxes
Lifecycle, services, network access, and forking in detail.
PostgreSQL
Run PostgreSQL the same way, with its data directory on an Archil disk.
Sharing disks
Mount modes, and reading a disk from several machines.
TypeScript SDK
Full reference for sandboxes, disks, and serverless execution.