Search code examples
node.jspostgresqlamazon-ec2amazon-rdssequelize-cli

Connect to postgres RDS from ec2 using Sequelize


I created an ec2 instance, in default VPC, and configured my node.js project as I do on my local machine. I created RDS postgres instance in the default VPC and permitted all the traffic. After this I tried to run migrations from ec2 with "npx sequelize-cli db:migrate" but the answer was only:

Sequelize CLI [Node: 14.2.0, CLI: 5.5.1, ORM: 5.21.2]

Loaded configuration file "database/config/config.js".
Using environment "development".

Than I connected to the db from my local machine and run the same command and it worked also installed psql on EC2 instance and I can connect to the RDS instance and see all the tables created from local machine. When I run migrations from local machine I get the answer above plus the logs from migrations. It looks like I am not able to connect to RDS instance from ec2 using sequelize but using psql it works. Also, it works to connect to RDS using node server on ec2 but sequelize cli doesn't.

Environment

Sequelize version: 5.21.2

Node.js version: v14.3.0

Operating System: ami-0a9e2b8a093c02922 and Ubuntu Server 18.04 LTS same behaviour

What should I do to run migrations from ec2 using Sequalize?


Solution

  • Solution for this problem is to install a version < 14 for node js. Install nvm ( node version manager) on the EC2 and then install a node js version < 14. Run again npm install in the project folder and then run the migrations + seeds and all should work.