Skip to content

Remote clusters ​

Pre-requisites ​

Starting the tunnel ​

The tunnel command opens an SSH tunnel to the Aurora cluster and forwards it to localhost:5432.

bash
luna -e <env> aurora tunnel start

Valid environments are polaris, pulsar, staging, and production.

The tunnel script retrieves the SSH key automatically from Parameter Store at /luna/aurora-ssh-tunnel/luna-bastion on first use and saves it to ~/.ssh/luna-bastion-non-prod.pem (or luna-bastion-prod.pem for production). The key file is reused on subsequent runs.

Stop it with:

bash
luna -e <env> aurora tunnel stop

Check tunnel status with:

bash
luna -e <env> aurora tunnel status

Exporting the connection string ​

Once the tunnel is running you can connect to the cluster directly using any Postgres client:

bash
export DATABASE_URL="postgresql://username:password@localhost:5432/oltp"

Credentials for named users are stored in Secrets Manager at <env>/aurora/users/<username>.

Running migrations remotely ​

The run-migration command handles the tunnel automatically — you do not need to start it manually first.

bash
luna -e <env> aurora run-migration --database <database>

Replace <database> with the target database name (e.g. oltp, activities). The command connects using the <env>/aurora/users/db-migrater secret, except for the activities database which uses the master credentials secret (<env>-aurora-credentials) because the aws_lambda extension requires rds_superuser.

Creating a user ​

bash
luna -e <env> aurora create-user \
  --username <name> \
  --database <database> \
  --file <filename>

The --file argument is the filename of a SQL template from the CLI's bundled users/ directory — not an arbitrary path. Available templates:

  • default-user.sql — creates a login role with no grants
  • tech-lead-user.sql — creates a login role with full DML access, schema creation rights, and default privileges for future objects
  • test-user.sql — creates a login role with full DML access on current and future tables, suitable for test environments

The SQL templates use , , and as placeholders, which the CLI substitutes before execution. A password is auto-generated if --password is not supplied.

The generated credentials are stored in Secrets Manager at <env>/aurora/users/<username>. A custom secret name can be specified with --secret-name, but it must start with <env>/aurora/users/.

Granting permissions for new tables ​

After running a migration that adds new tables, existing users need their permissions updated:

bash
luna -e <env> aurora grant-permissions \
  --username <name> \
  --database <database> \
  --file <filename>

The --file argument is the filename of a SQL template from the CLI's bundled permissions/ directory — not an arbitrary path. Available templates:

  • db-migrater.sql — full privileges on all tables and sequences, plus schema creation rights (used by the migration role)
  • read-only.sql — SELECT on all current and future tables and sequences
  • tech-lead.sql — full DML and function execution on all current tables and sequences; run this after migrations to restore tech lead access to newly created objects

Made with ❤️ by the Luna team