cphill cphill - 3 months ago 25
MySQL Question

Issue Connecting to RDS Endpoint with EC2 Instance through EB

I am having an issue with my Elasticbeantalk environment where the EC2 instance is not allowed to connect to my RDS instance. I can't seem to determine why this might be because I configured the RDS security group to allow MYSQL connection for any IP and have the same inbound rule in my EC2 instance security group. I tested my endpoint connection from my command line with

nc -zv test-db.cffvlzfsdafasf6x7kir.us-east-2.rds.amazonaws.com 3306
and
I Connection to ... succeeded!
as a response, which indicates there isn't an issue with my security group on the RDS instance, but in my EC2 instance log I have
Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
.

Here is my connection via Sequelize and I checked the username and password for my environment variables, which I confirmed are correct:

var Sequelize = require('sequelize');
var path = require('path');
var sequelize = new Sequelize(process.env.LOCAL_DATABASE, process.env.RDS_DATABASE || process.env.LOCAL_USERNAME, process.env.RDS_USERNAME || process.env.LOCAL_PASSWORD, process.env.RDS_PASSWORD, {
host: process.env.RDS_HOSTNAME || 'localhost',
port: process.env.RDS_PORT || '3306',
dialect: 'mysql'
});


Any suggestions of a checklist that I should perform or where I might be going wrong?

Answer

This part is all wrong:

var sequelize = new Sequelize(process.env.LOCAL_DATABASE, process.env.RDS_DATABASE || process.env.LOCAL_USERNAME, process.env.RDS_USERNAME || process.env.LOCAL_PASSWORD, process.env.RDS_PASSWORD, {
    host: process.env.RDS_HOSTNAME || 'localhost',
    port: process.env.RDS_PORT || '3306',
    dialect: 'mysql'
});

You somehow managed to put a || where you needed to put a , and a , where you should have put a ||. Try this:

var sequelize = new Sequelize(process.env.LOCAL_DATABASE || process.env.RDS_DATABASE, 
        process.env.LOCAL_USERNAME || process.env.RDS_USERNAME, 
        process.env.LOCAL_PASSWORD || process.env.RDS_PASSWORD, {
    host: process.env.RDS_HOSTNAME || 'localhost',
    port: process.env.RDS_PORT || '3306',
    dialect: 'mysql'
});
Comments