AWS Advanced Node.js Wrapper
The AWS Advanced Node.js Wrapper enhances Node.js database drivers with AWS-specific features for Amazon Aurora and RDS databases.
Latest Version: 2.0.1
Repository: github.com/aws/aws-advanced-nodejs-wrapper
Installation
npm install aws-advanced-nodejs-wrapper
Quick Start
PostgreSQL:
const { AwsPgClient } = require('aws-advanced-nodejs-wrapper');
const client = new AwsPgClient({
host: 'db-instance.cluster-xyz.us-east-1.rds.amazonaws.com',
database: 'mydb',
user: 'username',
password: 'password',
plugins: 'failover,iam'
});
await client.connect();
const result = await client.query('SELECT 1');
await client.end();
MySQL:
const { AwsMySQLClient } = require('aws-advanced-nodejs-wrapper');
const client = new AwsMySQLClient({
host: 'db-instance.cluster-xyz.us-east-1.rds.amazonaws.com',
database: 'mydb',
user: 'username',
password: 'password',
plugins: 'failover,iam'
});
await client.connect();
const [rows] = await client.query('SELECT 1');
await client.end();
Key Features
- Failover Plugin: Fast failover for Aurora clusters
- IAM Authentication Plugin: AWS IAM database authentication
- Secrets Manager Plugin: Automatic credential retrieval
- Read/Write Splitting Plugin: Query routing optimization
- Aurora Connection Tracker Plugin: Enhanced connection management
- Driver Support: Compatible with pg (PostgreSQL) and mysql2 (MySQL)
Configuration
Enable and configure plugins:
const client = new AwsPgClient({
plugins: 'failover,iam,secretsManager',
failoverTimeoutMs: 60000,
clusterId: 'my-cluster'
});
Common Configurations
Basic Failover
const { AwsPgClient } = require('aws-advanced-nodejs-wrapper');
const client = new AwsPgClient({
host: 'cluster.region.rds.amazonaws.com',
database: 'mydb',
user: 'username',
password: 'password',
plugins: 'failover'
});
await client.connect();
const result = await client.query('SELECT 1');
await client.end();
IAM Authentication
const client = new AwsPgClient({
host: 'cluster.region.rds.amazonaws.com',
database: 'mydb',
user: 'iamuser',
plugins: 'failover,iam',
region: 'us-east-1'
});
await client.connect();
Secrets Manager
const client = new AwsPgClient({
plugins: 'failover,secretsManager',
secretId: 'arn:aws:secretsmanager:region:account:secret:name',
region: 'us-east-1'
});
await client.connect();
Read/Write Splitting
const client = new AwsPgClient({
host: 'cluster.region.rds.amazonaws.com',
database: 'mydb',
user: 'username',
password: 'password',
plugins: 'failover,readWriteSplitting'
});
await client.connect();
// Reads go to reader
const users = await client.query('SELECT * FROM users');
// Writes go to writer
await client.query('INSERT INTO users VALUES ($1, $2)', ['name', 'email']);
MySQL Example
const { AwsMySQLClient } = require('aws-advanced-nodejs-wrapper');
const client = new AwsMySQLClient({
host: 'cluster.region.rds.amazonaws.com',
database: 'mydb',
user: 'username',
password: 'password',
plugins: 'failover,iam'
});
await client.connect();
const [rows] = await client.query('SELECT 1');
await client.end();
Connection Pooling
const { AwsPgPool } = require('aws-advanced-nodejs-wrapper');
const pool = new AwsPgPool({
host: 'cluster.region.rds.amazonaws.com',
database: 'mydb',
user: 'username',
password: 'password',
plugins: 'failover',
max: 20,
idleTimeoutMillis: 30000
});
const client = await pool.connect();
try {
const result = await client.query('SELECT * FROM users');
} finally {
client.release();
}
await pool.end();