I'm trying to write a Lambda function (in nodejs) which executes a simple SQL query. The database is an Aurora Postgres. I have set up function configuration for VPC access, worked fine with a MySQL database.
As you can see in the following, I'm using the "pg" node module (https://github.com/brianc/node-postgres). app.js
// For example, this function times out
const { Client } = require('pg');
const config = {
user: '<MY_DB_USER>',
host: '<MY_HOST>',
database: '<MY_DB_NAME>',
password: '<MY_DB_PASSWORD>',
port: <MY_PORT>
};
var postgresClient = new Client(config);
module.exports.handler = (event, context, cb) => {
console.log('entered handler');
postgresClient
.connect()
.then(() => {
console.log('connected');
return postgresClient.end();
})
.then(() => cb())
.catch(cb);
};
Yet, when using a postgres database, the lambda function times out every time I invoke. I have set up the subnets and the Security Group.
I have also tried using Pool from the pg module, with no success.
Note that this functions runs locally with success... I can't figure out why the lambda fails when it is deployed.