我正在尝试使用“felixge / node-mysql”软件包从Lambda中托管的nodejs代码连接到我的Amazon RDS(MySQL)实例。我需要帮助才能找出我做错了什么。我收到“连接ETIMEDOUT”错误。我的代码托管在Lambda中,Lamda和RDS都属于同一帐户和区域。我还将RDSFullAccess策略附加到IAM角色。还可以从所有IP(无白名单/黑名单IP)访问RDS实例。
同时,我可以使用相同的凭据从我的本地MySQL Workbench连接。
这是我的代码:
var connection = mysql.createConnection({
host : 'xxxxxxxx.crhmtrscnbgt.us-east-1.rds.amazonaws.com',
user : 'my_user',
password : 'my_passowrd',
database : 'my_db',
port : '3306',
debug : true
});
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
var query = "SELECT * FROM users";
connection.query(query, function(err, rows) {
if (err) throw err;
console.log(rows);
});
输出是:
2016-04-12T13:32:34.367Z fa04401a-00b2-11e6-9a23-2dd70e33cc5d error connecting: Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (/var/task/node_modules/mysql/lib/Connection.js:412:13)
at Socket.g (events.js:180:16)
at Socket.emit (events.js:92:17)
at Socket._onTimeout (net.js:327:8)
at _makeTimerTimeout (timers.js:438:11)
at Timer.unrefTimeout [as ontimeout] (timers.js:502:5)
--------------------
at Protocol._enqueue (/var/task/node_modules/mysql/lib/protocol/Protocol.js:141:48)
at Protocol.handshake (/var/task/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at Connection.connect (/var/task/node_modules/mysql/lib/Connection.js:123:18)
at Object.Workout.save (/var/task/storage.js:32:24)
at Object.storage.saveWorkout (/var/task/storage.js:62:28)
at intentHandlers.NewExcerciseIntent (/var/task/intentHandlers.js:19:17)
at AlexaSkill.eventHandlers.onIntent (/var/task/AlexaSkill.js:65:27)
at AlexaSkill.requestHandlers.IntentRequest (/var/task/AlexaSkill.js:28:37)
at AlexaSkill.execute (/var/task/AlexaSkill.js:105:24)
at exports.handler (/var/task/index.js:9:19)
答案 0 :(得分:0)
我修好了。问题在于Lambda函数配置中的超时设置。它设置为3秒,但我的脚本需要超过10秒才能执行。这就是我收到ETIMEDOUT错误的原因。我将设置更改为30秒。现在没有问题,一切正常。