从节点MySQL连接到Amazon RDS(MySQL)时出错 [英] Error connecting to Amazon RDS (MySQL) from node-mysql

查看:117
本文介绍了从节点MySQL连接到Amazon RDS(MySQL)时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用"felixge/node-mysql"包从Lambda托管的nodejs代码连接到我的Amazon RDS(MySQL)实例.我需要帮助以找出我做错了什么.我收到连接ETIMEDOUT"错误.我的代码托管在Lambda中,而Lamda和RDS都具有相同的帐户和区域.我还将RDSFullAccess策略附加到了IAM角色上.还可以从所有IP(无白名单/黑名单IP)访问RDS实例.

I am trying to connect to my Amazon RDS (MySQL) instance from a nodejs code hosted in Lambda using the "felixge/node-mysql" package. I need help to find out what I am doing wrong. I am getting "connect ETIMEDOUT" error. My code is hosted in Lambda and both Lamda and RDS are of the same account and region. I have also attached the RDSFullAccess Policy to the IAM role. RDS instance is also accessible from all IPs(no whitelist/blacklisted IPs).

同时,我可以使用相同的凭据从本地MySQL Workbench连接.

At the same time, I am able to connect from my local MySQL Workbench with same credentials.

这是我的代码:

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)

推荐答案

我已修复它.问题在于Lambda函数配置中的超时设置.它设置为3秒,但是我的脚本需要10秒钟以上的时间才能执行.这就是我收到ETIMEDOUT错误的原因.我将设置更改为30秒.现在没有问题,一切正常.

I fixed it. The issue was with the timeout setting in Lambda function configuration. It was set to 3 sec, but my script needed more than 10 seconds to execute. That's the reason I got the ETIMEDOUT error. I changed the setting to 30 seconds. Now no issues, everything works fine.

这篇关于从节点MySQL连接到Amazon RDS(MySQL)时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆