Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Using Node.js to interact with Amazon Aurora DSQL - Amazon Aurora DSQL

Amazon Aurora DSQL is provided as a Preview service. To learn more, see Betas and Previews in the AWS Service Terms.

Amazon Aurora DSQL is provided as a Preview service. To learn more, see Betas and Previews in the AWS Service Terms.

Using Node.js to interact with Amazon Aurora DSQL

This section describes how to use Node.js to interact with Aurora DSQL.

Before you begin, make sure that you have created a cluster in Aurora DSQL. Also make sure that you have installed Node. You must have installed version 18 or higher. Use the following command to check which version you have.

node --version

Connect to your Aurora DSQL cluster and run queries

Use the following JavaScript to connect to your cluster in Aurora DSQL.

import { DsqlSigner } from "@aws-sdk/dsql-signer"; import pg from "pg"; import assert from "node:assert"; const { Client } = pg; async function example(clusterEndpoint) { let client; const region = "us-east-1"; try { // The token expiration time is optional, and the default value 900 seconds const signer = new DsqlSigner({ hostname: clusterEndpoint, region, }); const token = await signer.getDbConnectAdminAuthToken(); client = new Client({ host: clusterEndpoint, user: "admin", password: token, database: "postgres", port: 5432, // <https://node-postgres.com/announcements> for version 8.0 ssl: true }); // Connect await client.connect(); // Create a new table await client.query(`CREATE TABLE IF NOT EXISTS owner ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), name VARCHAR(30) NOT NULL, city VARCHAR(80) NOT NULL, telephone VARCHAR(20) )`); // Insert some data await client.query("INSERT INTO owner(name, city, telephone) VALUES($1, $2, $3)", ["John Doe", "Anytown", "555-555-1900"] ); // Check that data is inserted by reading it back const result = await client.query("SELECT id, city FROM owner where name='John Doe'"); assert.deepEqual(result.rows[0].city, "Anytown") assert.notEqual(result.rows[0].id, null) await client.query("DELETE FROM owner where name='John Doe'"); } catch (error) { console.error(error); } finally { client?.end() } Promise.resolve() } export { example }
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.