其他 Amazon CloudFormation 模板密钥 - Amazon Elastic Beanstalk
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

其他 Amazon CloudFormation 模板密钥

我们已经引入了 Amazon CloudFormation 诸如Resourcesfiles、和之类的配置文件密钥packages。Elastic Beanstalk 将配置文件 Amazon CloudFormation 内容添加到支持您的环境的模板中,因此 Amazon CloudFormation 您可以使用其他部分在配置文件中执行高级任务。

参数

参数是 Elastic Beanstalk 自己的自定义选项的替代项,您可以用来定义要在配置文件的其他位置使用的值。与自定义选项相似,您可以使用参数在一个位置,收集用户可配置值。与自定义选项不同,您不能使用 Elastic Beanstalk 的 API 来设置参数值,并且可以在模板中定义的参数数量受到限制。 Amazon CloudFormation

您可能想要使用参数的原因之一是让您的配置文件兼作 Amazon CloudFormation 模板。如果您使用参数而不是自定义选项,则可以使用配置文件在中 Amazon CloudFormation 创建与其自己的堆栈相同的资源。例如,您可能有一个配置文件用于向环境中添加用于测试的 Amazon EFS 文件系统,然后使用同一个文件创建独立的文件系统,不绑定到用于生产用途的环境生命周期。

以下示例演示使用参数在配置文件顶部收集用户可配置的值。

L oadbalancer-accesslogs-existingbucket .config — 参数
Parameters: bucket: Type: String Description: "Name of the Amazon S3 bucket in which to store load balancer logs" Default: "amzn-s3-demo-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 主题,并将其 ARN 导出到名称为。 Amazon CloudFormation NotificationTopicArn

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 参数的值。

L oadbalancer-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