12

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
Luciano Nascimento
  • 2,600
  • 2
  • 44
  • 80
  • Here are some similar/related questions: [1](https://stackoverflow.com/q/42821299), [2](https://stackoverflow.com/q/28425360), [3](https://stackoverflow.com/q/42535753) (just to link them all together) – djvg Sep 17 '18 at 12:31

2 Answers2

15

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
Luciano Nascimento
  • 2,600
  • 2
  • 44
  • 80
  • 8
    AWS added a 'test' option to container commands, so the if statement from crontab.sh can be moved into app.config after leader_only: `test: '[ "$PARAM1" == "MyAppEnv-Production" ]'` – choobablue Mar 18 '16 at 18:09
2

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.

tnichols
  • 635
  • 1
  • 8
  • 19