AWS Elastic Beanstalk:特定环境的.ebextensions

时间:2022-01-24 23:18:21

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

我在AWS Elastic Beanstalk上有两个环境:开发和生产。

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

我希望.ebextensions / app.config只能在Production环境中运行。有什么办法吗?


app.config:

的app.config:

container_commands:
  01-command:
    command: "crontab .ebextensions/cronjob"
    leader_only: true

2 个解决方案

#1


15  

According to TNICHOLS idea I found a solution:

根据TNICHOLS的想法,我找到了一个解决方案:


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

将环境PARAM1变量值更改为MyAppEnv-Production(或您想要的)。

app.config:

的app.config:

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

crontab.sh:

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

#2


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.

我不认为有一种简单的方法可以按照你的思维方式去做。您可以运行配置文件并执行第二个脚本(可能是cron.sh)。在cron.sh里面,您可以检查环境名称,然后相应地添加cronjobs。没有测试过,但我认为应该可行。

#1


15  

According to TNICHOLS idea I found a solution:

根据TNICHOLS的想法,我找到了一个解决方案:


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

将环境PARAM1变量值更改为MyAppEnv-Production(或您想要的)。

app.config:

的app.config:

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

crontab.sh:

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

#2


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.

我不认为有一种简单的方法可以按照你的思维方式去做。您可以运行配置文件并执行第二个脚本(可能是cron.sh)。在cron.sh里面,您可以检查环境名称,然后相应地添加cronjobs。没有测试过,但我认为应该可行。