我正在使用Lambda连接到作为VPC一部分的Postgres RDS实例。如果暂时没有调用Lambda函数,它将在执行约2分钟后收到以下错误:
could not connect to postgres { [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
当lambda函数重试时,它会成功连接到数据库并按原样执行。
使用node-postgres包为node.js编写Lambda函数。连接程序看起来像这样:
var client = new pg.Client(conString);
client.connect(function(err) {
console.log("client connected");
if(err) {
context.fail('Connection failed');
}
else { //do stuff }
}
日志显示它永远不会到达连接的客户端"在超时之前。在第一次尝试期间出了什么问题?
注意:如果在20-30分钟内再次调用lambda函数,则不会发生此超时并且函数执行成功。
答案 0 :(得分:-4)
这个问题也发生在我身上,几分钟后没有使用lambda,当我尝试在第一次尝试调用lambda函数时我得到了
{"的errorMessage":"连接 ETIMEDOUT"" ERRORTYPE":" SequelizeConnectionError""堆栈跟踪":[" Handshake._callback (/var/task/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:94:20)","Handshake.Sequence.end (/var/task/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)","Protocol.handleNetworkError (/var/task/node_modules/mysql/lib/protocol/Protocol.js:364:14)","Connection._handleNetworkError (/var/task/node_modules/mysql/lib/Connection.js:421:18)","Connection._handleConnectTimeout (/var/task/node_modules/mysql/lib/Connection.js:417:8)","Socket.g (events.js:260:16)"," emitNone(events.js:67:13)"," Socket.emit (events.js:166:7)"," Socket._onTimeout(net.js:318:8)"," _runOnTimeout (timers.js:524:11)"" _makeTimerTimeout (timers.js:515:3)"," Timer.unrefTimeout(timers.js:584:5)"]}
重试2-3次后才能正常工作