How can I run sequelize db:migrate on ElasticBeanstalk with env vars?
Running sequelize migrate fails since it cannot find the .env file.<
I resolve this error through running command in .ebextension/config_file.sh node vsersion is same which is using in the EB console
files: "/opt/elasticbeanstalk/hooks/appdeploy/pre/config_file.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo yum -y install nodejs
then
run command on terminal in your app directory:
./node_modules/.bin/sequelize db:migrate
its work for me!!
Don't forget to include the first two commands, the file migration.config that worked for me in .ebextensions looks like this
container_commands:
00_node_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
00_npm_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"
50-run-database-migrations:
command: "./node_modules/.bin/sequelize db:migrate"
leader_only: true
It looks like the ./node_modules/.bin/sequelize uses /usr/bin/env/node and will give you the following error:
/usr/bin/env: node: No such file or directory
Because apparently node is called nodejs... the first two container commands will take care of that.
See https://github.com/nodejs/node-v0.x-archive/issues/3911 for further reference
I just found out what's going on with environment variables. Try running the migration script without npm. It'll be something like:
./node_modules/.bin/sequelize db:migrate
This way, you'll get all the environment variables as you expect.
Are you sure your .env file is committed to your git repo? In general, it's not a good idea to commit a .env to git and use it in production. You should instead set environment variables in your Elastic Beanstalk dashboard under Software Configuration.
You could also use the eb command line utility as documented here.