

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

# 使用 `AWS::CloudFormation::Interface` 中繼資料組織 CloudFormation 參數
<a name="aws-cloudformation-interface"></a>

`AWS::CloudFormation::Interface` 是一種中繼資料金鑰，可定義參數在 CloudFormation 主控台中的分組和排序方式。預設情況下，當您在主控台中建立或更新堆疊時，主控台會依據輸入參數的邏輯 ID 字母順序來列出參數。使用此金鑰時，您可以定義自己的參數分組和排序，以讓使用者有效地指定參數值。例如，您可以將所有 EC2 相關參數分組為一個群組，而將所有 VPC 相關參數分組為另一個群組。

在中繼資料金鑰中，您可以指定要建立的群組、每個群組中所要包含的參數，以及主控台顯示群組內每個參數的順序。

也可以定義參數的標籤。標籤是要在主控台中顯示的易讀名稱或描述，而非參數的邏輯 ID。標籤有助使用者了解可為每個參數指定的值。例如，您可以為 `KeyPair` 參數設定 `Select an EC2 key pair` 標籤。

您在中繼資料金鑰中參考的所有參數都會宣告於範本的 `Parameters` 區段中。

**注意**  
只有 CloudFormation 主控台會使用`AWS::CloudFormation::Interface`中繼資料金鑰。 AWS CLI 而 API 呼叫不會使用此金鑰。

## 語法
<a name="aws-resource-cloudformation-interface-syntax"></a>

若要在您的 CloudFormation 範本中宣告此實體，請使用下列語法：

### JSON
<a name="aws-resource-cloudformation-interface-syntax.json"></a>

```
"Metadata" : {
  "AWS::CloudFormation::Interface" : {
    "ParameterGroups": [
      {
        "Label": {
          "default": "Group Label"
        },
        "Parameters": [
          "Parameter1",
          "Parameter2"
        ]
      }
    ],
    "ParameterLabels": {
      "Parameter1": {
        "default": "Friendly Name for Parameter1"
      }
    }
  }
}
```

### YAML
<a name="aws-resource-cloudformation-interface-syntax.yaml"></a>

```
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      - Label:
          default: Group Label
        Parameters:
          - Parameter1
          - Parameter2
    ParameterLabels:
      Parameter1:
        default: Friendly Name for Parameter1
```

## Properties
<a name="w2aac11c23c29c17c17"></a>

`ParameterGroups`  
參數群組類型清單；您可以在其中指定群組名稱、每個群組中的參數，以及參數的顯示順序。  
*必要*：否    
`Label`  
參數群組的名稱。  
*必要*：否  
`default`  
CloudFormation 主控台用來命名參數群組的預設標籤。  
*必要*：否  
*類型：*字串  
`Parameters`  
群組要包含之區分大小寫的參數邏輯 ID 清單。這些參數必須已在範本的 `Parameters` 區段內定義。一個參數只能包含在一個參數群組中。  
您不會在 `Other parameters` 群組中，按字母順序建立主控台所列出參數與參數群組的關聯。  
*必要*：否  
*類型*：字串值清單

`ParameterLabels`  
參數和其易讀名稱的映射；在建立或更新堆疊時，CloudFormation 主控台會顯示這些項目。  
*必要*：否    
參數標籤  
參數的標籤。此標籤定義易用的名稱或描述，建立或更新堆疊時，CloudFormation 主控台會在 **Specify Parameters (指定參數)** 頁面上顯示這些名稱或描述。參數標籤必須是有效參數的邏輯 ID (區分大小寫)，而且這些參數必須已在範本的 `Parameters` 區段中宣告。  
*必要*：否  
`default`  
CloudFormation 主控台用來命名參數的預設標籤。  
*必要*：否  
*類型：*字串

## 範例
<a name="w2aac11c23c29c17c19"></a>

下列範例定義兩個參數群組：`Network Configuration` 和 `Amazon EC2 Configuration`。`Network Configuration` 群組包含 `VPCID`、`SubnetId` 和 `SecurityGroupID` 參數，這些參數是在範本的 `Parameters` 區段中定義 (未顯示)。在主控台中，這些參數的顯示順序是由參數的列出順序來定義，從 `VPCID` 參數開始。本範例會以類似方式來分組和排序 `Amazon EC2 Configuration` 參數。

本範例也會定義 `VPCID` 參數的標籤。主控台會顯示 **Which VPC should this be deployed to? (此項目應該部署至哪個 VPC？)** 而非參數的邏輯 ID (`VPCID`)。

### JSON
<a name="aws-cloudformation-interface-example.json"></a>

```
"Metadata" : {
  "AWS::CloudFormation::Interface" : {
    "ParameterGroups" : [
      {
        "Label" : { "default" : "Network Configuration" },
        "Parameters" : [ "VPCID", "SubnetId", "SecurityGroupID" ]
      },
      {
        "Label" : { "default":"Amazon EC2 Configuration" },
        "Parameters" : [ "InstanceType", "KeyName" ]
      }
    ],
    "ParameterLabels" : {
      "VPCID" : { "default" : "Which VPC should this be deployed to?" }
    }
  }
}
```

### YAML
<a name="aws-cloudformation-interface-example.yaml"></a>

```
Metadata: 
  AWS::CloudFormation::Interface: 
    ParameterGroups: 
      - Label: 
          default: "Network Configuration"
        Parameters: 
          - VPCID
          - SubnetId
          - SecurityGroupID
      - Label: 
          default: "Amazon EC2 Configuration"
        Parameters: 
          - InstanceType
          - KeyName
    ParameterLabels: 
      VPCID: 
        default: "Which VPC should this be deployed to?"
```

### 主控台中的參數群組
<a name="w2aac11c23c29c17c19c11"></a>

下圖會使用此範例的中繼資料金鑰來說明建立或更新堆疊時，主控台會如何顯示參數群組：**主控台中的參數群組** 

![\[主控台，其中顯示此範例的參數群組。\]](http://docs.aws.amazon.com/zh_tw/AWSCloudFormation/latest/UserGuide/images/console-create-stack-parameter-groups.png)
