Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Elastic Beanstalk: .ebextensions for a specific Environment

I have two Environments at AWS Elastic Beanstalk: Development and Production.

I would like that .ebextensions/app.config only run on Production environment. Theres any way to do that?


app.config:

container_commands:
  01-command:
    command: "crontab .ebextensions/cronjob"
    leader_only: true
like image 980
Luciano Nascimento Avatar asked Jun 04 '13 21:06

Luciano Nascimento


2 Answers

According to TNICHOLS idea I found a solution:


Change the environment PARAM1 variable value to MyAppEnv-Production (or what you want).

app.config:

container_commands:
  command-01:
    command: "/bin/bash .ebextensions/crontab.sh"
    leader_only: true

crontab.sh:

if [ "$PARAM1" == "MyAppEnv-Production" ]; then
  crontab -l > /tmp/cronjob

  #CRONJOB RULES
  echo "00 00 * * * /usr/bin/wget http://localhost/cronexecute > /dev/null 2>&1" >> /tmp/cronjob

  crontab /tmp/cronjob
  rm /tmp/cronjob
  echo 'Script successful executed, crontab updated.'
else
  echo 'This script is only executed in the production environment.'
fi
like image 159
Luciano Nascimento Avatar answered Dec 30 '22 14:12

Luciano Nascimento


I don't think there's a simple way to do it in the way you're thinking. You could have the config file run and execute a second script (perhaps cron.sh). Inside cron.sh you can check the environment name and then add the cronjobs accordingly. Haven't tested it, but I think that should work.

like image 20
tnichols Avatar answered Dec 30 '22 12:12

tnichols