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=
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?
我使用上面的代码从表返回一行。我在本地使用lambda-local执行,并在AWS中上传执行,我从AWS/local获得了一段时间。我认为这与查询有关。on,如果我在最后一个括号前添加context.done(null,“success”),它将返回一个success。如何让它返回查询中的行?
1 个解决方案
#1
3
schoolboy error, Turns out I need to allow AWS traffic through to my postgres server via the security group.
学生错误,我需要允许AWS流量通过安全组传输到我的postgres服务器。
',
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);
});
};
var pg = require("pg");
exports.handler = func