Skip to content

Instantly share code, notes, and snippets.

Last active June 12, 2021 03:12
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Run AWS Elastic Beanstalk container commands based on environment
# check for environemt within command to use leader flag
command: 'if [ "$SYMFONY_ENV" != "staging" ]; then cat .ebextensions/cronjobs/portfolio_cron_job.txt > /etc/cron.d/portfolio_cron_job && chmod 644 /etc/cron.d/portfolio_cron_job; else echo "dont include portfolio cron";fi'
leader_only: true
# command should run on all instances, we can use the test command for environment check
command: cat .ebextensions/cronjobs/synch_cron.txt > /etc/cron.d/synch_cron && chmod 644 /etc/cron.d/synch_cron
test: '[ "$SYMFONY_ENV" == "develop" ]'

Since AWS Elastic Beanstalk does not provide different .ebextension scripts based on environment I'm using a little workaround to solve this.


  • You need to declare an environment variable in your AWS EB application. (in my case SYMFONY_ENV)
  • now you can read this variable in your deployment scripts

pay attention:

  • You can not use the leader flag with the test command together. The test flag will overwrite the leader boolean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment