简体   繁体   中英

Connection refused when connecting with sequelize to aws rds

I have tried to connect to aws rds in every way possible and I'm getting a connection refused error when using sequelize so I wonder if there's a setting I need to set or include when making the connection. The code works on my local machine and if I push to heroku, however I need to use the aws instance for this project.

I used the sequelize CLI to generate an index.js file and the code for that is:

var path      = require('path');
var Sequelize = require('sequelize');
var basename  = path.basename(__filename);
const config    = require(path.join(__dirname,'../config/config.js'));
const db        = {};

console.log('config: ',config);

if (config.env === 'production') {
    console.log('i ran');
  var sequelize = new Sequelize(config.use_env_variable);
} else {
    console.log('else ran');
      var sequelize = new Sequelize(config.db.database, config.db.username, config.db.password, {
      dialect:config.db.dialect});
}

the error that is being thrown is: 在此处输入图像描述

as you can see the config variable is doing it's thing and I've made sure the env variables are set. I've triple checked to make sure the username and password were correct. I also tried using the end point that aws provides instead of localhost but that failed too. I've made sure to change the security settings on aws to allow any IP address to access it and I've successfully used mysql workbench to connect so there must be something else specific to sequelize or the code I'm using correct ?

UPDATE my config.js file is as such: 在此处输入图像描述

In case anyone comes across this with connection issues to amazon...

Your host is set to "localhost", but this must be set to the host that you're connecting to (not from). In aws rds case this will look something like this:

some-rds-name-inserted-here.74389nctj.eu-west-2.rds.amazonaws.com

检查您的 RDS 网络是否可以限制在不同的区域。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM