Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions content/features/1-connecting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ client.query('SELECT NOW()', (err, res) => {
})
```

Many cloud providers include alternative methods for connecting to database instances using short-lived authentication tokens. node-postgres supports dynamic passwords via a callback function, either synchronous or asynchronous. The callback function must resolve to a string.

```js
const { Pool } = require('pg')
const { RDS } = require('aws-sdk')

const signerOptions = {
credentials: {
accessKeyId: 'YOUR-ACCESS-KEY',
secretAccessKey: 'YOUR-SECRET-ACCESS-KEY',
},
region: 'us-east-1',
hostname: 'example.aslfdewrlk.us-east-1.rds.amazonaws.com',
port: 5432,
username: 'api-user',
}

const signer = new RDS.Signer()

const getPassword = () => signer.getAuthToken(signerOptions)

const pool = new Pool({
host: signerOptions.hostname,
port: signerOptions.port,
user: signerOptions.username,
database: 'my-db',
password: getPassword,
})
```

### Programmatic Connection to Sockets

Connections to unix sockets can also be made. This can be useful on distros like Ubuntu, where authentication is managed via the socket connection instead of a password.
Expand Down