Skip to main content

Infrastructure

PropertyValue
ProviderAWS Lightsail
Plan$5/month (1 GB RAM, 1 vCPU, 40 GB SSD)
Regioneu-north-1 (Stockholm)
Instancedbhost-1
Static IP13.61.204.171
OSUbuntu 22.04 LTS
SSH keyLightsailDefaultKey-eu-north-1

Firewall

PortProtocolSourcePurpose
22TCPRestrictedSSH access
443TCPAnyHTTPS (Caddy to agent)
6432TCPAnyPgBouncer (database connections)
In production, restrict port 6432 to known IP ranges (Vercel, your office) using the Lightsail firewall.

Initial setup

1

Create the Lightsail instance

Create an Ubuntu 22.04 instance in your preferred region. Attach a static IP.
2

Install PostgreSQL

sudo apt update
sudo apt install -y postgresql postgresql-contrib
sudo systemctl enable postgresql
Set the superuser password:
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your-secure-password';"
3

Install PgBouncer

sudo apt install -y pgbouncer
Configure /etc/pgbouncer/pgbouncer.ini:
[databases]
; Agent will add entries here

[pgbouncer]
listen_addr = 0.0.0.0
listen_port = 6432
auth_type = scram-sha-256
auth_file = /etc/pgbouncer/userlist.txt
pool_mode = transaction
max_client_conn = 200
default_pool_size = 20
max_prepared_statements = 100
sudo systemctl enable pgbouncer
sudo systemctl start pgbouncer
4

Install Caddy

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
Configure /etc/caddy/Caddyfile:
agent.dbhost.app {
    reverse_proxy localhost:8420
}
sudo systemctl reload caddy
5

Install Python 3.12+

sudo apt install -y python3.12 python3.12-venv
Install uv (fast Python package manager):
curl -LsSf https://astral.sh/uv/install.sh | sh
6

Create agent directory

sudo mkdir -p /opt/dbhost /var/backups/postgresql
sudo chown ubuntu:ubuntu /opt/dbhost /var/backups/postgresql
7

Deploy the agent

DNS

Configure these records at your domain registrar:
RecordTypeValue
@AVercel IP
wwwCNAMEcname.vercel-dns.com
agentA13.61.204.171