Reputation: 177
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?
Upvotes: 3
Views: 1444
Reputation: 177
schoolboy error, Turns out I need to allow AWS traffic through to my postgres server via the security group.
Upvotes: 3