Skip to content

Local development ​

Start the local database ​

The luna-oltp-schema package ships a docker-compose.yml that starts a PostgreSQL 16 container on port 5432 attached to the luna-local Docker network (the same network SAM uses).

bash
cd packages/luna-oltp-schema
yarn db:local:start

This starts a container named luna-oltp-local with:

  • User: luna_user
  • Password: luna_pass
  • Database: luna_oltp

Stop it with:

bash
yarn db:local:stop

Push migrations ​

Apply all pending migrations to the local database:

bash
cd packages/luna-oltp-schema
yarn db:migrations:local:push

This runs drizzle-kit push against the local container. You need the container running first.

Seed data locally ​

The seed command requires the --database flag, the ENVIRONMENT variable, and DATABASE_URL pointing at the local container:

bash
DATABASE_URL=postgresql://luna_user:luna_pass@localhost:5432/luna_oltp \
ENVIRONMENT=local luna aurora seed --database oltp

DATABASE_URL is required because AuroraDatabase.getClient uses it to open a direct Postgres connection in local mode — without it the factory throws an error. You need the container running and migrations applied first.

This populates the local database with reference data. Check cli/src/commands/aurora/commands/seed/database-seed-configs.ts for what is seeded per database.

Invoke the Lambda with SAM ​

  1. Build the service:

    bash
    cd services/<service-name>
    yarn build
  2. Create env.local.json in the service root with the local database URL and environment:

    json
    {
      "KudosOltpStreamsFunction": {
        "ENVIRONMENT": "local",
        "DATABASE_URL": "postgres://luna_user:luna_pass@luna-oltp-local:5432/luna_oltp"
      }
    }

    Replace KudosOltpStreamsFunction with the logical ID of the function you are invoking (as it appears in application.yml).

    The ENVIRONMENT=local variable is required — AuroraDatabase uses it to switch from AWS Data API mode to a direct Postgres connection via DATABASE_URL.

  3. Invoke the function:

    bash
    sam local invoke KudosOltpStreamsFunction \
      --event oltp-streams/__test__/events/sample-ddb-stream.json \
      --env-vars env.local.json \
      --docker-network luna-local

The --docker-network luna-local flag is required so that the Lambda container can reach the Postgres container.

Drizzle Studio ​

Drizzle Studio is a browser-based database UI. Start it with:

bash
cd packages/luna-oltp-schema
yarn db:studio:start

Then open the URL prompted in your terminal. You need the local database running first.

Note on DOCKER_HOST ​

If SAM cannot find Docker (common on macOS with Docker Desktop), export the socket path before invoking:

bash
export DOCKER_HOST=unix:///Users/<your-username>/.docker/run/docker.sock

Note on SAM local invoke ​

Depending on the version of the SAM CLI, it may require AWS credentials in order to run. You can get around this by defining the variables with mock values before running:

bash
AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake AWS_DEFAULT_REGION=eu-west-1 \
sam local invoke ...

Made with ❤️ by the Luna team