本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
其他 Amazon CloudFormation 模板密钥
我们已从 Amazon CloudFormation 中引入配置文件密钥,如 Resources
、files
和 packages
。Elastic Beanstalk 会将配置文件的内容添加到支持您的环境的 Amazon CloudFormation 模板中,这样您便可以使用其他 Amazon CloudFormation 部分在配置文件中执行高级任务。
参数
参数是 Elastic Beanstalk 自己的自定义选项的替代项,您可以用来定义要在配置文件的其他位置使用的值。与自定义选项相似,您可以使用参数在一个位置,收集用户可配置值。与自定义选项不同,您不能使用 Elastic Beanstalk 的 API 来设置参数值,并且模板中可以定义的参数数量受 限制Amazon CloudFormation
您可能想要使用参数的一个原因是使您的配置文件是 Amazon CloudFormation 模板的两倍。如果您使用参数而不是使用自定义选项,则可以使用配置文件在 Amazon CloudFormation 中创建与它自己的堆栈中相同的资源。例如,您可能有一个配置文件用于向环境中添加用于测试的 Amazon EFS 文件系统,然后使用同一个文件创建独立的文件系统,不绑定到用于生产用途的环境生命周期。
以下示例演示使用参数在配置文件顶部收集用户可配置的值。
例 Loadbalancer-accesslogs-existingbucket.config – 参数
Parameters:
bucket:
Type: String
Description: "Name of the Amazon S3 bucket in which to store load balancer logs"
Default: "DOC-EXAMPLE-BUCKET
"
bucketprefix:
Type: String
Description: "Optional prefix. Can't start or end with a /, or contain the word AWSLogs"
Default: ""
输出
您可以使用 Outputs
数据块,将有关已创建资源的信息导出到 Amazon CloudFormation。然后,您可以使用 Fn::ImportValue
函数将值拉入到 Elastic Beanstalk 之外的 Amazon CloudFormation 模板中。
以下示例创建 Amazon SNS 主题并使用名称 NotificationTopicArn
将它的 ARN 导出到 Amazon CloudFormation。
例 sns-topic.config
Resources:
NotificationTopic:
Type: AWS::SNS::Topic
Outputs:
NotificationTopicArn:
Description: Notification topic ARN
Value: { "Ref" : "NotificationTopic" }
Export:
Name: NotificationTopicArn
在其他环境的配置文件中,或者 Elastic Beanstalk 之外的 Amazon CloudFormation 模板中,您可以使用 Fn::ImportValue
函数获取导出的 ARN。此示例将导出的值分配给名为 TOPIC_ARN
的环境属性。
例 env.config
option_settings:
aws:elasticbeanstalk:application:environment:
TOPIC_ARN: '`{ "Fn::ImportValue" : "NotificationTopicArn" }`'
映像
您可以使用映射,来存储按命名空间组织的键-值对。映射可以帮助组织您在配置中使用的值,或根据其它值来更改参数值。例如,以下配置根据当前区域来设置账户 ID 参数的值。
例 Loadbalancer-accesslogs-newbucket.config – 映射
Mappings:
Region2ELBAccountId:
us-east-1:
AccountId: "111122223333"
us-west-2:
AccountId: "444455556666"
us-west-1:
AccountId: "123456789012"
eu-west-1:
AccountId: "777788889999"
...
Principal:
AWS:
? "Fn::FindInMap"
:
- Region2ELBAccountId
-
Ref: "AWS::Region"
- AccountId