node-postgres
node-postgres copied to clipboard
Timeout in lambda trying to connect to Aurora Serverless V1 cluster
Context:
We are trying to switch from data-api-client to pg. Our setup is: Aurora serverelss V1 PostgresSQL 11.16 cluster. However, we are not able to connect - instead the connection always times out. We made sure the cluster is running with capacity units.
Expected behavior
Using pg can connect to cluster.
Actual behavior
It always times out.
Steps to reproduce
const { Pool } = require('pg');
const pool = new Pool({
host: <host>,
port: 5432,
username: <username>,
password: < password >,
});
exports.handler = async function (event, context, callback) {
context.callbackWaitsForEmptyEventLoop = false; // !important to reuse pool
const client = await pool.connect();
try {
const res = await client.query('SELECT $1::text as message', [
'Hello world!',
]);
callback(null, res.rows[0].message);
} finally {
client.release(true);
}
};
Environment
- Version of pg: 8.10.0
- OS type (Linux/Windows/Mac): Within AWS Lambda running on node.js v14
- Version of Node.js: v14
Notes
The lambda is placed in the same VPC as the Aurora cluster and has the RDS-Data permissions:
Allow: rds-data:BatchExecuteStatement
Allow: rds-data:BeginTransaction
Allow: rds-data:CommitTransaction
Allow: rds-data:ExecuteStatement
Allow: rds-data:RollbackTransaction
hey, @thomasklein , did you manage to solve? I'm facing the same issue here.
Where is the timeout happening? In the call to await pool.connect()
?