Where should migrations be run on elasticbeanstalk deployment process?
You can try the flag: leader_only
in an ebextensions
configuration file. This flag will make your migration run just once even if you have the app deployed in many instances. For example, save this file into the root directory of your project at the path: /.ebextensions/migration.config
option_settings:
container_commands:
database_migration:
leader_only: true
command: "db migrate"
More information: AWS Elastic Beanstalk Official Docs
As the OP didn't specify the platform, I thought I'd add a specific .ebextensions/migration.config
config for Ruby on Rails, as I encountered this exact issue as well:
container_commands:
12migrate:
command: rake db:migrate
leader_only: true