简体   繁体   English

使用 sequelize 连接到 aws rds 时连接被拒绝

[英]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.我已尝试以各种可能的方式连接到 aws rds,但在使用 sequelize 时出现连接被拒绝错误,所以我想知道在建立连接时是否需要设置或包含设置。 The code works on my local machine and if I push to heroku, however I need to use the aws instance for this project.该代码在我的本地机器上运行,如果我推送到 heroku,但是我需要为这个项目使用 aws 实例。

I used the sequelize CLI to generate an index.js file and the code for that is:我使用 sequelize CLI 生成一个 index.js 文件,其代码是:

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.如您所见,配置变量正在执行此操作,并且我已确保设置了 env 变量。 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.我还尝试使用 aws 提供的端点而不是 localhost 但也失败了。 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 ?我已确保更改 aws 上的安全设置以允许任何 IP 地址访问它,并且我已成功使用 mysql 工作台进行连接,因此必须有其他特定于 sequelize 或我使用的代码正确的东西?

UPDATE my config.js file is as such:更新我的 config.js 文件是这样的: 在此处输入图像描述

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).您的主机设置为“localhost”,但这必须设置为您要连接的主机(而不是来自)。 In aws rds case this will look something like this:在 aws rds 情况下,这将如下所示:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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