Elastic Beanstalk条件container_commands无法正常工作

问题描述 投票:0回答:1

我有两个Elastic Beanstalk服务器用于相同的代码库。一个是生产,一个是分期。

我正在尝试使用条件container_command来创建一个只能在生产中运行的crontab。这些条件语句适用于常规commands,但似乎总是评估为container_commands为真。但是,根据其他SO帖子和示例,它们应该对两种类型的命令都一样。

这就是我想要做的:

container_commands:
  01_activate_cronjob:
    test: '[ "${BEANSTALK_ENVIRONMENT}" == "production" ]'
    command: "cat .ebextensions/my_cron_file > /etc/cron.d/my_cron_file && chmod 644 /etc/cron.d/my_cron_file"
    leader_only: true

BEANSTALK_ENVIRONMENT是我的beanstalk配置中设置的Elastic Beanstalk变量,我已经确认echo $BEANSTALK_ENVIRONMENT分别输出“production”和“staging”。

我也试过这个test线:

test: test $BEANSTALK_ENVIRONMENT == production

此外,我已在终端验证了这些测试命令的正确性。

test $BEANSTALK_ENVIRONMENT == production && echo yes || echo no
# outputs "yes" on the production server and "no" on the staging server

我知道我可以通过在command部分中插入条件语句来破解/解决这个问题;然而,正如我之前所说,网上的一切都表明这应该有效,所以我很难过。

amazon-web-services amazon-elastic-beanstalk
1个回答
1
投票

根据AWS docs你只能使用testleader_only之一,如果你同时使用两者,leader_only将获胜:

命令可以是仅限领导者或具有测试,但不是两者(leader_only优先)。

如果您在特定用例中肯定需要leader_only,我会重新考虑。

© www.soinside.com 2019 - 2024. All rights reserved.