Registry / database / aws-secure-postgres

aws-secure-postgres

JSON →
library1.0.6jsnpmunverified

A lightweight Node.js library that generates AWS RDS IAM authentication tokens and creates secure PostgreSQL connections. Current stable version: 1.0.6, with low release cadence. It handles the token generation, SSL enforcement, and connection parameter configuration automatically, reducing the boilerplate for RDS IAM auth. Compared to manually using the AWS SDK and pg library, it provides a single function call to get a fully configured pool or client.

npm install aws-secure-postgres
INSTALL
IMPORT
SIG · AWS-SECURE-POSTGRE
A
aws-secure-postgres
databasejavascriptv1.0.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SecurePostgres
import SecurePostgres from 'aws-secure-postgres'
const SecurePostgres = require('aws-secure-postgres')
Package exports a default class. ESM import recommended; CommonJS require may work if package supports it.
default export
import SecurePostgres from 'aws-secure-postgres'
import { SecurePostgres } from 'aws-secure-postgres'
The package has only a default export, not a named export. Named import will result in undefined.
SecurePostgres
const SecurePostgres = require('aws-secure-postgres').default
const SecurePostgres = require('aws-secure-postgres')
In CommonJS, you need to access .default because the export is via module.exports.default.

Shows how to import SecurePostgres, create an instance with RDS connection details, get a configured pg.Pool, and run a query.

import SecurePostgres from 'aws-secure-postgres'; // or const SecurePostgres = require('aws-secure-postgres').default; const sp = new SecurePostgres({ region: 'us-east-1', host: 'mydb.cluster-xxxxx.us-east-1.rds.amazonaws.com', port: 5432, dbUser: 'db_user', database: 'mydb', ssl: true }); // Get a pg.Pool configured with IAM auth token const pool = sp.getPool(); // Query using the pool pool.query('SELECT NOW()', (err, res) => { console.log(err ? err : res.rows); pool.end(); });
Debug
Known issues
breakingThe package only supports IAM authentication for RDS PostgreSQL. If you are using a non-RDS database, this package will not work.
fix
Use a different library or manually configure IAM auth with the AWS SDK.
affects: all
deprecatedThe package may not be actively maintained. At version 1.0.6 with low release cadence, it may not support the latest AWS SDK v3.
fix
Consider using the AWS SDK v3 and pg directly, or check for updates.
affects: <=1.0.6
gotchaThe constructor does not validate the input parameters. Invalid configurations will only fail at query time with cryptic errors.
fix
Validate that region, host, dbUser, and database are provided and correct before creating the instance.
affects: all
gotchaThe IAM token has a 15-minute expiration. Long-running applications need to regenerate tokens periodically.
fix
Implement token refresh logic using the getPool() method or manually refresh tokens before expiration.
affects: all
Errors
Common errors & fixes
TypeError: SecurePostgres is not a constructor
Using require('aws-secure-postgres') without .default in CommonJS.
fix
Use const SecurePostgres = require('aws-secure-postgres').default;
Error: getaddrinfo ENOTFOUND
The host provided is incorrect or not reachable.
fix
Double-check the RDS endpoint hostname. Ensure the instance is in the same VPC and security groups allow inbound connections.
Error: password authentication failed for user
IAM token is expired or invalid, or the database user is not configured for IAM auth.
fix
Ensure the RDS instance has IAM authentication enabled and the database user has the appropriate permissions. Then generate a new token.
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies
aws-sdkrequiredRequired to generate RDS IAM authentication tokens using the AWS SDK.
pgrequiredUsed to create and manage PostgreSQL connections.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
aws-secure-postgres — npm install aws-secure-postgres · libregistry