Skip to content

Instantly share code, notes, and snippets.

@josefaidt
Created March 4, 2025 16:55
Show Gist options
  • Save josefaidt/826c8d247084793ef11ac5c9c39a81fe to your computer and use it in GitHub Desktop.
Save josefaidt/826c8d247084793ef11ac5c9c39a81fe to your computer and use it in GitHub Desktop.
scrappy demo script for using drizzle to interact with Amazon Aurora DSQL
import { DsqlSigner } from "@aws-sdk/dsql-signer"
import { drizzle } from "drizzle-orm/node-postgres"
import pg from "pg"
const { Client } = pg
const id = "<your-database-id>" as const
const endpoint = `${id}.dsql.us-east-1.on.aws` as const
const region = "us-east-1" as const
// https://docs.aws.amazon.com/aurora-dsql/latest/userguide/SECTION_program-with-nodejs.html
const signer = new DsqlSigner({
hostname: endpoint,
region,
})
const token = await signer.getDbConnectAdminAuthToken()
const client = new Client({
host: endpoint,
user: "admin",
password: token,
database: "postgres",
port: 5432,
// <https://node-postgres.com/announcements> for version 8.0
ssl: true,
})
const db = drizzle({ client })
// important! explicit `connect()`
await db.$client.connect()
const result = await db.execute("select 1")
console.log({ result })
await db.$client.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment