Kev*_*vin 36 amazon-web-services amazon-elastic-beanstalk
是否可以从.ebextensions配置文件引用PARAM1/PARAM2等容器环境属性.如果是这样,怎么样?我试过$ PARAM1,但它似乎是一个空值.
我想设置在启动时的主机名包含DEV,QA和PROD,我通过PARAM1环境变量传递给我的容器.
commands:
01-set-correct-hostname:
command: hostname myappname{$PARAM1}.com
Run Code Online (Sandbox Code Playgroud)
Kev*_*vin 26
事实证明,您只能在该container_commands部分中执行此操作,而不是commands部分.
这有效:
container_commands:
01-set-correct-hostname:
command: "hostname myappname{$PARAM1}.com"
Run Code Online (Sandbox Code Playgroud)
小智 10
这对我有用.我尝试了接受的方法,但没有产生预期的结果(输出中包含花括号).上传到Elastic Beanstalk时从.config文件执行的命令排除故障也是一个挑战(或者我只是不确切地知道在哪里查看).
AWS环境:
Elastic Beanstalk环境属性(配置 - >软件配置 - >环境属性):
示例.config文件包含在部署工件中的.ebextensions文件夹中:
container_commands:
0_test-variable:
cwd: /tmp
command: "touch ${HELLO_VARIABLE}_0_.txt"
1_test-variable:
cwd: /tmp
command: "touch {$HELLO_VARIABLE}_1_.txt"
2_test-variable:
cwd: /tmp
command: "touch $HELLO_VARIABLE_2_.txt"
Run Code Online (Sandbox Code Playgroud)
使用Elastic Beanstalk部署工件后,EC2实例中的/ tmp目录将包含以下文件(注意大括号和$的位置):
小智 7
为了在命令阶段使环境变量可用,我将它们解析为bash源文件.
000001.envvars.config
...
commands:
000001_envvars_to_bash_source_file:
command: |
# source our elastic beanstalk environment variables
/opt/elasticbeanstalk/bin/get-config --output YAML environment|perl -ne "/^\w/ or next; s/: /=/; print qq|\$_|" > /var/tmp/envvars
chmod 400 /var/tmp/envvars
...
Run Code Online (Sandbox Code Playgroud)
然后我用: -
source /var/tmp/envvars
Run Code Online (Sandbox Code Playgroud)
在后续命令中.
接受的答案已经过时了.
现在您可以使用/opt/elasticbeanstalk/support/envvars已经准备好来源的shell脚本:
commands:
01_update_composer:
command: |
. /opt/elasticbeanstalk/support/envvars
/usr/bin/composer.phar self-update
container_commands:
01_run_composer:
command: |
composer.phar install --no-scripts --no-dev # already has user-specified env variables
Run Code Online (Sandbox Code Playgroud)
更新:
经过深入调查后发现,container_commands:包括你的环境变量,但commands:没有.
| 归档时间: |
|
| 查看次数: |
13564 次 |
| 最近记录: |