.ebextensions "files:" 部分中的环境变量
Env Variable in .ebextensions "files:" section
我在 AWS Elastic Beanstalk 的软件配置选项卡中定义了一个名为 MY_ENVIRONMENT_VARIABLE 的环境变量。
现在我想在 .ebextensions 配置文件的 "files:" 部分使用这个环境变量。
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 脚本),但我找不到任何在 [=20= 中可能引用的引用] 部分。
有没有人有关于如何在 "files:" 部分中使用环境变量的示例?
使用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
属性是可选的,在找不到环境变量的情况下使用。
以上配置文件将创建文件 /tmp/application.properties
,其内容来自环境变量 MY_ENVIRONMENT_VARIABLE
中引用的文件。
我在 AWS Elastic Beanstalk 的软件配置选项卡中定义了一个名为 MY_ENVIRONMENT_VARIABLE 的环境变量。
现在我想在 .ebextensions 配置文件的 "files:" 部分使用这个环境变量。
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 脚本),但我找不到任何在 [=20= 中可能引用的引用] 部分。
有没有人有关于如何在 "files:" 部分中使用环境变量的示例?
使用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
属性是可选的,在找不到环境变量的情况下使用。
以上配置文件将创建文件 /tmp/application.properties
,其内容来自环境变量 MY_ENVIRONMENT_VARIABLE
中引用的文件。