@aws/aurora-dsql-node-postgres-connector

中文文档
0.1.9发布于 2026/05/20Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 15万

An AWS Aurora DSQL connector with IAM authentication for node-postgres

原始使用文档
文档目录19 节
  1. About the Connector
  2. What is Aurora DSQL Authentication?
  3. Features
  4. Example Application
  5. Quick start guide
  6. Requirements
  7. ⚠️ Important
  8. Installation
  9. Peer Dependencies
  10. Usage
  11. Client Connection
  12. Pool Connection
  13. Advanced Usage
  14. OCC Retry
  15. Configuration Options
  16. Authentication
  17. Admin vs Regular Users
  18. Development
  19. License

Aurora DSQL Connector for node-postgres

GitHub License NPM Version Discord chat

The Aurora DSQL Connector for node-postgres is a Node.js connector built on node-postgres that integrates IAM Authentication for connecting JavaScript/TypeScript applications to Amazon Aurora DSQL clusters.

The Aurora DSQL Connector is designed as an authentication plugin that extends the functionality of the node-postgres' Client and Pool to enable applications to authenticate with Amazon Aurora DSQL using IAM credentials.

About the Connector

Amazon Aurora DSQL is a cloud-native distributed database with PostgreSQL compatibility. While it requires IAM authentication and time-bound tokens, traditional Node.js database drivers lack this built-in support.

The Aurora DSQL Connector for node-postgres bridges this gap by implementing an authentication middleware that works seamlessly with node-postgres. This approach allows developers to maintain their existing node-postgres code while gaining secure IAM-based access to Aurora DSQL clusters through automated token management.

What is Aurora DSQL Authentication?

In Aurora DSQL, authentication involves:

  • IAM Authentication: All connections use IAM-based authentication with time-limited tokens
  • Token Generation: Authentication tokens are generated using AWS credentials and have configurable lifetimes

The Aurora DSQL Connector for node-postgres is designed to understand these requirements and automatically generate IAM authentication tokens when establishing connections.

Features

  • Automatic IAM Authentication - Handles DSQL token generation and refresh
  • Built on node-postgres - Leverages the popular PostgreSQL client for Node.js
  • Seamless Integration - Works with existing node-postgres connection patterns
  • Region Auto-Discovery - Extracts AWS region from DSQL cluster hostname
  • Full TypeScript Support - Provides full type safety
  • AWS Credentials Support - Supports various AWS credential providers (default, profile-based, custom)
  • Connection Pooling Compatibility - Works seamlessly with built-in connection pooling
  • OCC Retry - Automatic retry with exponential backoff on optimistic concurrency conflicts

Example Application

There is an included sample application in example that shows how to use Aurora DSQL Connector for node-postgres. To run the included example please refer to the example README.

Quick start guide

Requirements

  • Node.js 20+
  • Access to an Aurora DSQL cluster
  • Set up appropriate IAM permissions to allow your application to connect to Aurora DSQL.
  • AWS credentials configured (via AWS CLI, environment variables, or IAM roles)

⚠️ Important

  • Running this code might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.

Installation

npm install @aws/aurora-dsql-node-postgres-connector

Peer Dependencies

npm install @aws-sdk/credential-providers @aws-sdk/dsql-signer pg tsx
npm install --save-dev @types/pg

Usage

Client Connection

// src/index.ts
import { AuroraDSQLClient } from "@aws/aurora-dsql-node-postgres-connector";

const client = new AuroraDSQLClient({
  host: "<CLUSTER_ENDPOINT>",
  user: "admin",
});
await client.connect();
const result = await client.query("SELECT NOW()");
await client.end();

Pool Connection

// src/index.ts
import { AuroraDSQLPool } from "@aws/aurora-dsql-node-postgres-connector";

const pool = new AuroraDSQLPool({
  host: "<CLUSTER_ENDPOINT>",
  user: "admin",
  max: 3,
  idleTimeoutMillis: 60000,
});

const result = await pool.query("SELECT NOW()");

Advanced Usage

// index.ts
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { AuroraDSQLClient } from "@aws/aurora-dsql-node-postgres-connector";

const client = new AuroraDSQLClient({
  host: "example.dsql.us-east-1.on.aws",
  user: "admin",
  customCredentialsProvider: fromNodeProviderChain(), // Optionally provide custom credentials provider
});

await client.connect();
const result = await client.query("SELECT NOW()");
await client.end();

OCC Retry

Aurora DSQL uses optimistic concurrency control (OCC). Transactions that conflict are rejected at commit time with error codes OC000, OC001, or 40001. The connector provides a transaction() method that automatically retries on these conflicts with exponential backoff.

import { AuroraDSQLPool } from "@aws/aurora-dsql-node-postgres-connector";

const pool = new AuroraDSQLPool({
  host: "<CLUSTER_ENDPOINT>",
  user: "admin",
  retry: { maxRetries: 5 },
});

await pool.transaction(async (client) => {
  await client.query("INSERT INTO accounts(id, balance) VALUES($1, $2)", [1, 100]);
});

The retry config accepts a partial object — unset fields use defaults:

FieldDefaultDescription
maxRetries3Number of retry attempts after the initial try (0 = no retry)
baseDelayMs1Initial backoff delay in ms
maxDelayMs100Maximum base backoff delay in ms (jitter is added on top)
jitterFactor0.25Jitter as a fraction of delay

Per-call override:

await pool.transaction(callback, { maxRetries: 0 }); // no retry for this call

Configuration Options

OptionTypeRequiredDescription
hoststringYesDSQL cluster hostname
userstringYesDSQL username
databasestringNoDatabase name
regionstringNoAWS region (auto-detected from hostname if not provided)
portnumberNoDefault to 5432
customCredentialsProviderAwsCredentialIdentity / AwsCredentialIdentityProviderNoCustom AWS credentials provider
profilestringNoThe IAM profile name. Default to "default"
tokenDurationSecsnumberNoToken expiration time in seconds
retryPartial<OCCRetryConfig>NoOCC retry configuration (see above)
loggerLoggerNoLogger with warn and error methods (e.g. console)

All other parameters from Client / Pool are supported.

Authentication

The connector automatically handles DSQL authentication by generating tokens using the DSQL client token generator. If the AWS region is not provided, it will be automatically parsed from the hostname provided.

For more information on authentication in Aurora DSQL, see the user guide.

Admin vs Regular Users

  • Users named "admin" automatically use admin authentication tokens
  • All other users use regular authentication tokens
  • Tokens are generated dynamically for each connection

Development

# Install dependencies
npm install

# Build the project
npm run build

# Set a cluster for use in the tests
export CLUSTER_ENDPOINT=your-cluster.dsql.us-east-1.on.aws

# Run tests
npm run test

License

This software is released under the Apache 2.0 license.

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

版本与发布记录

@aws/aurora-dsql-node-postgres-connector 共发布 10 个版本,首次发布于 2025/10/30;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.9latest2026/05/205 个月前
0.1.82026/02/069 个月前
0.1.72025/12/3110 个月前
0.1.62025/12/2310 个月前
0.1.52025/12/1310 个月前
0.1.42025/12/1210 个月前

关于 @aws/aurora-dsql-node-postgres-connector 的常见问题

@aws/aurora-dsql-node-postgres-connector 是什么?

An AWS Aurora DSQL connector with IAM authentication for node-postgres

如何安装 @aws/aurora-dsql-node-postgres-connector?

在项目目录运行 npm install @aws/aurora-dsql-node-postgres-connector,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:pg(^8.16.3)、pg-connection-string(^2.7.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aws/aurora-dsql-node-postgres-connector 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aws/aurora-dsql-node-postgres-connector 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aws/aurora-dsql-node-postgres-connector 可以商用吗?

@aws/aurora-dsql-node-postgres-connector 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws/aurora-dsql-node-postgres-connector 的下载量有多少?

根据 npm 官方下载统计,@aws/aurora-dsql-node-postgres-connector 在 2026/10/08 – 2026/11/06 这 30 天内被下载 150,301 次,日均约 5,010 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws/aurora-dsql-node-postgres-connector 还在维护吗?

最新版本 0.1.9 发布于 2026/05/20(5 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 9 个;首次发布于 2025/10/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。