I had the same exact issue and after many hours of debugging various logs I found that this was the log I needed to actually look at to isolate the real issue with sequelize migrations. The container_commands script from the original question is actually correct and the error lies elsewhere in your app. (At least in my case)
Assuming you've already configured Elastic Beanstalk with .elasticbeanstalk and .ebextensions folders where .ebextensions folder contains a file named something like 01_run_migrations.config
that holds these container_commmands below:
container_commands:
00_node_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
01_npm_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"
03_db_migrate:
command: ./node_modules/.bin/sequelize db:migrate
leader_only: true
Debugging Logs
If your deploy fails after running eb deploy
try using eb ssh
from within your project folder to debug the various server logs. Here are two logs that were helpful for me to take a look at once ssh'd into the environment.
cat /var/log/cfn-init.log
and
cat /var/log/cfn-init-cmd.log
The second one led me to the exact stack trace source of the error which turned out to be a misconfiguration of my sequelize config.js file. I'm using Postgres and had incorrectly setup my production config.
Take a look at Sequelize config.js
If you were getting this error for the same reason I was for configuring Postgres, then it's due to a bad configuration of your sequelize config.js file for your production environment.
Did NOT Work
{
database: process.env.RDS_DB_NAME,
username: process.env.RDS_USERNAME,
password: process.env.RDS_PASSWORD,
host: process.env.RDS_HOSTNAME,
logging: false,
dialect: "postgres",
dialectModule: require("pg"),
port: process.env.RDS_PORT,
maxConcurrentQueries: 100,
dialectOptions: {
ssl: "Amazon RDS",
multipleStatements: true
},
pool: { maxConnections: 5, maxIdleTime: 30 },
language: "en",
}
Did Work
{
database: process.env.RDS_DB_NAME,
username: process.env.RDS_USERNAME,
password: process.env.RDS_PASSWORD,
host: process.env.RDS_HOSTNAME,
logging: false,
dialect: "postgres",
port: process.env.RDS_PORT,
maxConcurrentQueries: 100,
ssl: "Amazon RDS",
pool: { maxConnections: 5, maxIdleTime: 30 },
language: "en",
}
Although, I don't know if this will solve your exact problem, I hope sharing this will help others more easily isolate and debug issues with Elastic Beanstalk container_commands. Oh, I should also note that running eb logs
wasn't exactly helpful in my case.