

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

# 其他 CloudFormation 模板密钥
<a name="ebextensions-otherkeys"></a>

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

**Topics**
+ [参数](#ebextensions-otherkeys-parameters)
+ [输出](#ebextensions-otherkeys-outputs)
+ [映像](#ebextensions-otherkeys-mappings)

## 参数
<a name="ebextensions-otherkeys-parameters"></a>

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

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

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

**Example [L oadbalancer-accesslogs-existingbucket .config](https://github.com/awsdocs/elastic-beanstalk-samples/tree/main/configuration-files/aws-provided/resource-configuration/loadbalancer-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: ""
```

## 输出
<a name="ebextensions-otherkeys-outputs"></a>

您可以使用 `Outputs` 数据块，将有关已创建资源的信息导出到 CloudFormation。然后，你可以使用该`Fn::ImportValue`函数将该值提取到 Elastic Beanstalk 之外的 CloudFormation 模板中。

以下示例创建了一个 Amazon SNS 主题，并将其 ARN 导出到名称为。 CloudFormation `NotificationTopicArn`

**Example [sns-topic.config](https://github.com/awsdocs/elastic-beanstalk-samples/tree/main/configuration-files/aws-provided/resource-configuration/sns-topic.config)**  

```
Resources:
  NotificationTopic:
    Type: AWS::SNS::Topic

Outputs:
  NotificationTopicArn:
    Description: Notification topic ARN
    Value: { "Ref" : "NotificationTopic" }
    Export:
      Name: NotificationTopicArn
```

在其他环境的配置文件或 Elastic Beanstalk 之外的 CloudFormation 模板中，`Fn::ImportValue`您可以使用该函数来获取导出的 ARN。此示例将导出的值分配给名为 `TOPIC_ARN` 的环境属性。

**Example env.config**  

```
option_settings:
  aws:elasticbeanstalk:application:environment:
    TOPIC_ARN: '`{ "Fn::ImportValue" : "NotificationTopicArn" }`'
```

## 映像
<a name="ebextensions-otherkeys-mappings"></a>

您可以使用映射，来存储按命名空间组织的键-值对。映射可以帮助组织您在配置中使用的值，或根据其它值来更改参数值。例如，以下配置根据当前区域来设置账户 ID 参数的值。

**Example [L oadbalancer-accesslogs-newbucket .config](https://github.com/awsdocs/elastic-beanstalk-samples/tree/main/configuration-files/aws-provided/resource-configuration/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
```