I have a node.js application running on an EC2 instance (running Ubuntu) trying to connect to MySQL on RDS. The security group for the RDS instance contains the security group for the EC2 instance as an authorized entry. Both instances are in the same zone, us-east-1c.
When I attempt to connect to RDS using MySQL CLI using mysql -u xxxxx -h xxxxx.xxxxxx.us-east-1.rds.amazonaws.com -p
I connect without any problems.
However, when I attempt to connect using an RDS connection test utility I've written, I get an Error: connect ECONNREFUSED
. The test utility code is:
var mysql = require('mysql');
mysqlConfiguration = 'production';
var mysqlConfigs = {
'production':{
host:'xxxxx.xxxxx.us-east-1.rds.amazonaws.com',
password:'xxxxx',
user:'xxxxx',
database:'xxxxx'
},
}
var connectionPool = mysql.createPool({
host: mysqlConfigs[mysqlConfiguration]['host'],
user: mysqlConfigs[mysqlConfiguration]['user'],
password: mysqlConfigs[mysqlConfiguration]['password'],
database: mysqlConfigs[mysqlConfiguration]['database'],
multipleStatements: true,
connectionLimit: 50,
});
connectionPool.getConnection(function(err,db){
console.log(err);
console.log(db);
if(db) db.release();
});
The error I receive indicates that the connection is refused. When I run this code on my dev machine (which is whitelisted with the RDS instance), it connects normally to RDS.
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
fatal: true }
It's very strange how I can connect using mysql from the command line but I can't from the node.js application.
I've looked at EC2 iptables outbound defaults in the EC2 documentation and it says all outbound traffic is allowed.
Any ideas why this is happening?