我们正在尝试将环境特定的应用程序配置文件存储在 s3 中。这些文件存储在不同的子目录中,这些子目录以环境命名,并且环境也作为文件名的一部分。
例子是
dev/application-dev.properties
stg/application-stg.properties
prd/application-prd.properties
Elastic Beanstalk 环境被命名为dev、stg、prd,或者我还在 Elastic Beanstalk 中定义了一个名为 ENVIRONMENT 的环境变量,它可以是dev、stg 或 prd。
我现在的问题是,从 .ebextensions 中的配置文件下载配置文件时,如何引用环境名称或 ENVIRONMENT 变量?
{"Ref": "AWSEBEnvironmentName" }
我尝试在 .ebextensions/myapp.config 中使用引用,但在部署时出现语法错误。
.ebextensions/myapp.config 的内容是:
files:
/config/application-`{"Ref": "AWSEBEnvironmentName" }`.properties:
mode: "000666"
owner: webapp
group: webapp
source: https://s3.amazonaws.com/com.mycompany.mybucket/`{"Ref": "AWSEBEnvironmentName" }`/application-`{"Ref": "AWSEBEnvironmentName" }`.properties
authentication: S3Access
Resources:
AWSEBAutoScalingGroup:
Metadata:
AWS::CloudFormation::Authentication:
S3Access:
type: S3
roleName: aws-elasticbeanstalk-ec2-role
buckets: com.mycompany.api.config
我得到的错误是:
The configuration file .ebextensions/myapp.config in application version
manualtest-18 contains invalid YAML or JSON. YAML exception: Invalid Yaml:
mapping values are not allowed here in "<reader>", line 6, column 85:
... .config/stg/application-`{"Ref": "AWSEBEnvironmentName" }`.prop ... ^ ,
JSON exception: Invalid JSON: Unexpected character (f) at position 0..
Update the configuration file.
在 AWS Elastic Beanstalk 的 .ebextensions 配置文件中引用环境变量的正确方法是什么?