.ebextensions“文件:"中的Env变量.部分 [英] Env Variable in .ebextensions "files:" section
问题描述
我在AWS Elastic Beanstalk的软件配置"选项卡中定义了一个名为MY_ENVIRONMENT_VARIABLE的环境变量.
I defined an environment variable called MY_ENVIRONMENT_VARIABLE in AWS Elastic Beanstalk's Software Configuration tab.
现在,我想在.ebextensions配置文件的文件:"部分中使用此环境变量.
Now I would like to use this environment variable in the "files:" section of a .ebextensions config file.
Resources:
AWSEBAutoScalingGroup:
Metadata:
AWS::CloudFormation::Authentication:
S3Auth:
type: S3
buckets: arn:aws:s3:::SomeS3Bucket
roleName: aws-elasticbeanstalk-ec2-role
files:
"/tmp/application.properties" :
mode: "000644"
owner: root
group: root
source: { "Ref" : "MY_ENVIRONMENT_VARIABLE" }
authentication: S3Auth
container_commands:
01-apply-configuration:
command: mv /tmp/application.properties .
似乎可以在"container_commands:"部分中引用环境变量(通过使用bash脚本),但是我在"files:"部分中找不到任何可能的引用.
It seems to be possible to reference environment variables in the "container_commands:" section (by using bash scripts) but I couldn't find any references that it is possible inside the "files:" section.
有人在文件:"部分中有一个如何使用环境变量的示例吗?
Does anybody have an example of how to use environment variables inside the "files:" section?
推荐答案
使用命名空间
Use Fn::GetOptionSetting to retreive environment variables. Environment variables are in aws:elasticbeanstalk:application:environment
namespace
files:
"/tmp/application.properties" :
mode: "000644"
owner: root
group: root
source: '`{"Fn::GetOptionSetting": {"Namespace": "aws:elasticbeanstalk:application:environment", "OptionName": "MY_ENVIRONMENT_VARIABLE", "DefaultValue": "file_path"}}`'
authentication: S3Auth
请注意执行命令替换的backtick
. DefaultValue
属性是可选的,在找不到环境变量的情况下使用.
Note the backtick
which perform the command substitution. DefaultValue
attribute is optional, which is used in case environment variable is not found.
上面的配置文件将使用环境变量MY_ENVIRONMENT_VARIABLE
中引用的文件中的内容创建文件/tmp/application.properties
.
Above config file will create file /tmp/application.properties
with content from the file referenced in environment variable MY_ENVIRONMENT_VARIABLE
.
这篇关于.ebextensions“文件:"中的Env变量.部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!