

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

# 建立多變體功能旗標
<a name="appconfig-creating-multi-variant-feature-flags-procedures"></a>

使用本節中的程序來建立特徵標記的變體。

**開始之前**  
記下以下重要資訊。
+ 您可以編輯現有特徵標記的變體。您無法在建立新的*組態設定檔時，建立*新功能旗標的變體。您必須先完成建立新組態描述檔的工作流程。建立組態設定檔之後，您可以將變體新增至組態設定檔中的任何旗標。如需如何建立新的組態設定檔的資訊，請參閱 [在 中建立功能標記組態描述檔 AWS AppConfig](appconfig-creating-configuration-and-profile-feature-flags.md)。
+ 若要擷取 Amazon EC2、Amazon ECS 和 Amazon EKS 運算平台的功能標記變體資料，您必須使用 AWS AppConfig 代理程式版本 2.0.4416 或更新版本。
+ 基於效能考量， AWS CLI 和 SDK 呼叫 AWS AppConfig 不會擷取變體資料。如需 AWS AppConfig 代理程式的詳細資訊，請參閱 [如何使用 AWS AppConfig 代理程式擷取組態資料](appconfig-agent-how-to-use.md)。
+ 當您建立特徵標記變體時，您可以為其指定規則。規則是將請求內容做為輸入，並產生布林值結果做為輸出的表達式。建立變體之前，請檢閱支援的運算元和運算子，了解標記變體規則。您可以在建立變體之前建立規則。如需詳細資訊，請參閱[了解多變體特徵標記規則](appconfig-creating-multi-variant-feature-flags-rules.md)。

**Topics**
+ [

## 建立多變體功能旗標 （主控台）
](#appconfig-creating-multi-variant-feature-flags-procedures-console)
+ [

## 建立多變體特徵標記 （命令列）
](#appconfig-creating-multi-variant-feature-flags-procedures-commandline)

## 建立多變體功能旗標 （主控台）
<a name="appconfig-creating-multi-variant-feature-flags-procedures-console"></a>

下列程序說明如何使用 AWS AppConfig 主控台為現有組態描述檔建立多變體功能旗標。您也可以編輯現有的功能旗標來建立變體。

**建立多變體功能旗標**

1. 在 https：//[https://console.aws.amazon.com/systems-manager/appconfig/](https://console.aws.amazon.com/systems-manager/appconfig/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇**應用程式**，然後選擇應用程式。

1. 在**組態設定檔和功能旗標**索引標籤上，選擇現有的功能旗標組態設定檔。

1. 在**旗標**區段中，選擇**新增旗標**。

1. 在**特徵標記定義**區段中，針對**標記名稱**輸入名稱。

1. 針對**旗標索引鍵**輸入旗標識別符，以區分相同組態設定檔中的旗標。相同組態描述檔中的旗標不能有相同的金鑰。建立旗標之後，您可以編輯旗標名稱，但不能編輯旗標索引鍵。

1. （選用） 在**描述**欄位中，輸入此標記的相關資訊。

1. 在**變體**區段中，選擇**多變體旗標**。

1. （選用） 在**特徵標記屬性**區段中，選擇**定義屬性**。屬性可讓您在旗標中提供額外的值。如需屬性和限制條件的詳細資訊，請參閱 [了解特徵標記屬性](appconfig-creating-configuration-and-profile-feature-flags.md#appconfig-creating-configuration-profile-feature-flag-attributes)。

   1. 針對**金鑰**，指定旗標金鑰，然後從類型清單中選擇其**類型**。如需 **Value** and **Constraints** 欄位支援選項的相關資訊，請參閱先前參考的屬性章節。

   1. 選取**必要值**，指定是否需要屬性值。

   1. 選擇**定義屬性**以新增其他屬性。

   1. 選擇**套用**以儲存屬性變更。

1. 在**特徵標記變體**區段中，選擇**建立變體**。

   1. 針對**變體名稱**，輸入名稱。

   1. 使用**已啟用值**切換來啟用變體。

   1. 在**規則**文字方塊中，輸入規則。

   1. 使用上方**建立變體** > **建立變體**或**下方建立變體**選項，為此標記建立其他變體。

   1. 在**預設變體**區段中，使用**啟用值**切換來啟用預設變體。或者，為步驟 10 中定義的屬性提供值。

   1. 選擇**套用**。

1. 驗證旗標及其變體的詳細資訊，然後選擇**建立旗標**。

如需使用變體部署新功能旗標的詳細資訊，請參閱 [在 中部署功能旗標和組態資料 AWS AppConfig](deploying-feature-flags.md)。

## 建立多變體特徵標記 （命令列）
<a name="appconfig-creating-multi-variant-feature-flags-procedures-commandline"></a>

下列程序說明如何使用 AWS Command Line Interface （在 Linux 或 Windows 上） 或 Tools for Windows PowerShell，為現有的組態設定檔建立多變體功能旗標。您也可以編輯現有的功能旗標來建立變體。

**開始之前**  
使用 建立多變體功能旗標之前，請先完成下列任務 AWS CLI。
+ 建立特徵標記組態描述檔。如需詳細資訊，請參閱[在 中建立功能標記組態描述檔 AWS AppConfig](appconfig-creating-configuration-and-profile-feature-flags.md)。
+ 更新至最新版本的 AWS CLI。如需詳細資訊，請參閱《AWS Command Line Interface 使用者指南》**中的[安裝或更新最新版 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

**建立多變體功能旗標**

1. 在本機電腦上建立組態檔案，以指定您要建立之多變量旗標的詳細資訊。使用副檔名儲存`.json`檔案。檔案必須遵循 [https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-type-reference-feature-flags.html](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-type-reference-feature-flags.html) JSON 結構描述。組態檔案的結構描述內容如下。

   ```
   {
     "flags": {
       "FLAG_NAME": {
         "attributes": {
             "ATTRIBUTE_NAME": {
             "constraints": {
               "type": "CONSTRAINT_TYPE"
             }
           }
         },
         "description": "FLAG_DESCRIPTION",
         "name": "VARIANT_NAME"
       }
     },
     "values": {
       "VARIANT_VALUE_NAME": {
         "_variants": [
           {
             "attributeValues": {
               "ATTRIBUTE_NAME": BOOLEAN
             },
             "enabled": BOOLEAN,
             "name": "VARIANT_NAME",
             "rule": "VARIANT_RULE"
           },
           {
             "attributeValues": {
               "ATTRIBUTE_NAME": BOOLEAN
             },
             "enabled": BOOLEAN,
             "name": "VARIANT_NAME",
             "rule": "VARIANT_RULE"
           },
           {
             "attributeValues": {
               "ATTRIBUTE_NAME": BOOLEAN
             },
             "enabled": BOOLEAN,
             "name": "VARIANT_NAME",
             "rule": "VARIANT_RULE"
           },
           {
             "attributeValues": {
               "ATTRIBUTE_NAME": BOOLEAN
             },
             "enabled": BOOLEAN,
             "name": "VARIANT_NAME",
             "rule": "VARIANT_RULE"
           }
         ]
       }
     },
     "version": "VERSION_NUMBER"
   }
   ```

   以下是三個變體和預設變體的範例。

   ```
   {
     "flags": {
       "ui_refresh": {
         "attributes": {
           "dark_mode_support": {
             "constraints": {
               "type": "boolean"
             }
           }
         },
         "description": "A release flag used to release a new UI",
         "name": "UI Refresh"
       }
     },
     "values": {
       "ui_refresh": {
         "_variants": [
           {
             "attributeValues": {
               "dark_mode_support": true
             },
             "enabled": true,
             "name": "QA",
             "rule": "(ends_with $email \"qa-testers.mycompany.com\")"
           },
           {
             "attributeValues": {
               "dark_mode_support": true
             },
             "enabled": true,
             "name": "Beta Testers",
             "rule": "(exists key::\"opted_in_to_beta\")"
           },
           {
             "attributeValues": {
               "dark_mode_support": false
             },
             "enabled": true,
             "name": "Sample Population",
             "rule": "(split pct::10 by::$email)"
           },
           {
             "attributeValues": {
               "dark_mode_support": false
             },
             "enabled": false,
             "name": "Default Variant"
           }
         ]
       }
     },
     "version": "1"
   }
   ```

1. 使用 `CreateHostedConfigurationVersion` API 儲存您的特徵標記組態資料 AWS AppConfig。

------
#### [ Linux ]

   ```
   aws appconfig create-hosted-configuration-version \
     --application-id APPLICATION_ID \
     --configuration-profile-id CONFIGURATION_PROFILE_ID \
     --content-type "application/json" \
     --content file://path/to/feature_flag_configuration_data.json \
     --cli-binary-format raw-in-base64-out \
     outfile
   ```

------
#### [ Windows ]

   ```
   aws appconfig create-hosted-configuration-version ^
     --application-id APPLICATION_ID ^
     --configuration-profile-id CONFIGURATION_PROFILE_ID ^
     --content-type "application/json" ^
     --content file://path/to/feature_flag_configuration_data.json ^
     --cli-binary-format raw-in-base64-out ^
     outfile
   ```

------
#### [ PowerShell ]

   ```
   New-APPCHostedConfigurationVersion `
     -ApplicationId APPLICATION_ID `
     -ConfigurationProfileId CONFIGURATION_PROFILE_ID `
     -ContentType "application/json" `
     -Content file://path/to/feature_flag_configuration_data.json `
     -Raw
   ```

------

   `service_returned_content_file` 包含您的組態資料，其中包含一些 AWS AppConfig 產生的中繼資料。
**注意**  
當您建立託管組態版本時， 會 AWS AppConfig 驗證您的資料是否符合 [https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-type-reference-feature-flags.html](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-type-reference-feature-flags.html) JSON 結構描述。 AWS AppConfig 此外， 會驗證資料中的每個特徵標記屬性是否符合您為這些屬性定義的限制。