

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 其他 CloudFormation 範本金鑰
<a name="ebextensions-otherkeys"></a>

我們已從 引入組態檔案金鑰`Resources`， CloudFormation 例如 `files`、 和 `packages`。Elastic Beanstalk 會將組態檔案的內容新增至支援您環境的 CloudFormation 範本，因此您可以使用其他 CloudFormation 區段在組態檔案中執行進階任務。

**Topics**
+ [Parameters](#ebextensions-otherkeys-parameters)
+ [輸出](#ebextensions-otherkeys-outputs)
+ [映射項目](#ebextensions-otherkeys-mappings)

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

參數可替代 Elastic Beanstalk 自己的[自訂選項](configuration-options-custom.md)，可用於定義您在組態檔案他處使用的值。如同自訂選項，您可使用參數在單一位置收集使用者可設定的值。與自訂選項不同，您無法使用 Elastic Beanstalk 的 API 來設定參數值，而且您可以在範本中定義的參數數量受到限制 CloudFormation。

您可能想要使用參數的一個原因是讓您的組態檔案成為 CloudFormation 範本的兩倍。如果您使用參數而非自訂選項，則可以使用組態檔案在 中建立 CloudFormation 與其堆疊相同的資源。例如，您的組態檔案可將 Amazon EFS 檔案系統新增至您的環境進行測試，然後使用相同檔案來建立未繫結至您環境生命週期的獨立檔案系統，供生產使用。

下列範例說明如何使用參數在組態檔案上方收集使用者可設定的值。

**Example [Loadbalancer-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 主題，並以 CloudFormation 名稱 將其 ARN 匯出至 `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 [Loadbalancer-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
```