Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NodeJs Postgres + AWS Lambda timeout even after successful client connect

Lambda Function:

const client = new Client({
    user: 'postgres',
    host: 'rds_host',
    database: 'dbname',
    password: 'db_password',
    port: 5432
});

exports.handler = async (event, context, callback) => {
    try {
        await client.connect();
        callback(null, "Connected Successfully");
    } catch (e) {
        callback(null, "Error");
    }
};

With this code my lambda always get a timeout error, if I get rid of the cliente.connect() line, it works fine.

The interesting part is that if I add a client.query with INSERT the command does work and the row is created at the DB, so why I get a timeout when the client.connect() is added and the connection works?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’m pretty sure that when your handler function is async, it’s expecting a promise to be resolved, so, instead of using the callback, I would just return "Connected Successfully";

Link to relevant docs

There’s an example at this link where there’s an async handler without the callback.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading