Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda postgres query is timing out

var pg = require("pg");

exports.handler = function(event, context) {

var conn = "blanked out for SO";
var client = new pg.Client(conn);
client.connect();

userName = event.userName;

var client = new pg.Client(conn);
client.connect();

var query = client.query({
    text: 'SELECT address from users where userName= $1',
    values: [userName]
});
query.on("row", function (row, result) {
   result.addRow(row);
});

query.on("end", function (result) {
    var jsonString = JSON.stringify(result.rows);
    var jsonObj = JSON.parse(jsonString);

    client.end();
    context.done(null, jsonObj);
   });
};

Im using the above code to return one row from a table. I execute locally using lambda-local and have uploaded to execute in AWS, i keep getting a time out from AWS/local. I believe it has got to do with the query.on, if I add a context.done(null,"success") to the end just before the last brace it will return a success. How do i get it to return the row from the query?

like image 667
Podgeypoos Avatar asked Jun 28 '26 22:06

Podgeypoos


1 Answers

schoolboy error, Turns out I need to allow AWS traffic through to my postgres server via the security group.

like image 123
Podgeypoos Avatar answered Jun 30 '26 12:06

Podgeypoos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!