

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

# 在 中建立組態設定檔 AWS AppConfig
<a name="appconfig-creating-configuration-profile"></a>

*組態資料*是影響應用程式行為的設定集合。*組態描述檔*包含一個 URI，該 URI 可讓 AWS AppConfig 將組態資料定位在其儲存的位置和組態類型。 AWS AppConfig 支援下列類型的組態描述檔：
+ **特徵標記**：您可以使用特徵標記來啟用或停用應用程式中的功能，或使用標記屬性來設定應用程式特徵的不同特性。 會以特徵標記格式將特徵標記組態 AWS AppConfig 儲存在 AWS AppConfig 託管組態存放區中，其中包含有關標記和標記屬性的資料和中繼資料。功能旗標組態的 URI 只是 `hosted`。
+ **自由格式組態**：自由格式組態可將資料存放在下列任何 AWS 服務 和 Systems Manager 工具中：
  + AWS AppConfig 託管組態存放區
  + Amazon Simple Storage Service
  + AWS CodePipeline
  + AWS Secrets Manager
  + AWS Systems Manager (SSM) 參數存放區
  + SSM 文件存放區

**注意**  
如果可能，我們建議您在 AWS AppConfig 託管組態存放區中託管您的組態資料，因為它提供最多的功能和增強功能。

以下是一些組態資料範例，可協助您更好地了解不同類型的組態資料，以及如何在功能旗標或不使用組態描述檔中使用它們。

 **特徵標記組態資料** 

下列功能標記組態資料會啟用或停用每個區域的行動付款和預設付款。

------
#### [ JSON ]

```
{
  "allow_mobile_payments": {
    "enabled": false
  },
  "default_payments_per_region": {
    "enabled": true
  }
}
```

------
#### [ YAML ]

```
---
allow_mobile_payments:
  enabled: false
default_payments_per_region:
  enabled: true
```

------

 **操作組態資料** 

下列自由格式組態資料會強制執行應用程式如何處理請求的限制。

------
#### [ JSON ]

```
{
  "throttle-limits": {
    "enabled": "true",
    "throttles": [
      {
        "simultaneous_connections": 12
      },
      {
        "tps_maximum": 5000
      }
    ],
    "limit-background-tasks": [
      true
    ]
  }
}
```

------
#### [ YAML ]

```
---
throttle-limits:
  enabled: 'true'
  throttles:
  - simultaneous_connections: 12
  - tps_maximum: 5000
  limit-background-tasks:
  - true
```

------

 **存取控制清單組態資料** 

下列存取控制清單自由格式組態資料會指定哪些使用者或群組可以存取應用程式。

------
#### [ JSON ]

```
{
  "allow-list": {
    "enabled": "true",
    "cohorts": [
      {
        "internal_employees": true
      },
      {
        "beta_group": false
      },
      {
        "recent_new_customers": false
      },
      {
        "user_name": "Jane_Doe"
      },
      {
        "user_name": "John_Doe"
      }
    ]
  }
}
```

------
#### [ YAML ]

```
---
allow-list:
  enabled: 'true'
  cohorts:
  - internal_employees: true
  - beta_group: false
  - recent_new_customers: false
  - user_name: Jane_Doe
  - user_name: Ashok_Kumar
```

------

**Topics**
+ [

# 在 中建立功能標記組態描述檔 AWS AppConfig
](appconfig-creating-configuration-and-profile-feature-flags.md)
+ [

# 在 中建立自由格式組態描述檔 AWS AppConfig
](appconfig-free-form-configurations-creating.md)
+ [

# 為非原生資料來源建立組態設定檔
](appconfig-creating-configuration-profile-other-data-sources.md)

# 在 中建立功能標記組態描述檔 AWS AppConfig
<a name="appconfig-creating-configuration-and-profile-feature-flags"></a>

您可以使用特徵標記來啟用或停用應用程式中的功能，或使用標記屬性來設定應用程式特徵的不同特性。 會以特徵標記格式將特徵標記組態 AWS AppConfig 儲存在 AWS AppConfig 託管組態存放區中，其中包含有關標記和標記屬性的資料和中繼資料。

**注意**  
當您建立特徵標記組態描述檔時，您可以建立基本特徵標記作為組態描述檔工作流程的一部分。 AWS AppConfig 也支援多變體特徵標記。*多變體功能旗標*可讓您定義一組可能的旗標值，以針對請求傳回。請求使用變體設定的旗標時，您的應用程式會提供根據一組使用者定義規則 AWS AppConfig 進行評估的內容。根據請求中指定的內容和為變體定義的規則， 會 AWS AppConfig 傳回不同的旗標值給應用程式。  
若要建立多變體功能旗標，請先建立組態設定檔，然後在組態設定檔中編輯任何旗標以新增變體。如需詳細資訊，請參閱[建立多變體功能旗標](appconfig-creating-multi-variant-feature-flags.md)。

**Topics**
+ [

## 了解特徵標記屬性
](#appconfig-creating-configuration-profile-feature-flag-attributes)
+ [

# 建立功能標記組態描述檔 （主控台）
](appconfig-creating-feature-flag-configuration-create-console.md)
+ [

# 建立特徵標記組態描述檔 （命令列）
](appconfig-creating-feature-flag-configuration-commandline.md)
+ [

# 建立多變體功能旗標
](appconfig-creating-multi-variant-feature-flags.md)
+ [

# 了解 的類型參考 AWS.AppConfig.FeatureFlags
](appconfig-type-reference-feature-flags.md)
+ [

# 將先前的特徵標記版本儲存到新版本
](appconfig-creating-configuration-profile-feature-flags-editing-version.md)

## 了解特徵標記屬性
<a name="appconfig-creating-configuration-profile-feature-flag-attributes"></a>

當您建立特徵標記組態描述檔，或在現有組態描述檔中建立新的標記時，您可以指定標記的屬性和對應的限制條件。屬性是您與特徵標記建立關聯的欄位，用於表達與特徵標記相關的屬性。屬性會與您的旗標索引鍵和旗標的 `enable`或 `disable`值一起交付到您的應用程式。

限制條件可確保未預期的任何屬性值不會部署到您的應用程式。下圖顯示範例。

![\[AWS AppConfig 特徵標記的標記屬性範例\]](http://docs.aws.amazon.com/zh_tw/appconfig/latest/userguide/images/appconfig-flag-attributes.png)


**注意**  
請注意下列有關旗標屬性的資訊。  
對於屬性名稱，會保留「啟用」一詞。您無法建立名為「啟用」的功能旗標屬性。沒有其他保留單字。
功能旗標的屬性只有在啟用該旗標時才會包含在`GetLatestConfiguration`回應中。
指定旗標的旗標屬性索引鍵必須是唯一的。

AWS AppConfig 支援下列類型的旗標屬性及其對應的限制條件。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/appconfig/latest/userguide/appconfig-creating-configuration-and-profile-feature-flags.html)

# 建立功能標記組態描述檔 （主控台）
<a name="appconfig-creating-feature-flag-configuration-create-console"></a>

使用下列程序，透過 AWS AppConfig 主控台建立 AWS AppConfig 特徵標記組態描述檔。在建立組態設定檔時，您也可以建立基本功能旗標。

**建立組態設定檔**

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

1. 在導覽窗格中，選擇**應用程式**，然後選擇您在 中建立的應用程式[在 中為您的應用程式建立命名空間 AWS AppConfig](appconfig-creating-namespace.md)。

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

1. 在**組態選項**區段中，選擇**功能旗標**。

1. 在**組態設定檔**區段的**組態設定檔名稱**中，輸入名稱。

1. （選用） 展開**描述**並輸入描述。

1. （選用） 展開**其他選項**，並視需要完成下列操作。

   1. 在**加密**清單中，從清單中選擇 AWS Key Management Service (AWS KMS) 金鑰。此客戶受管金鑰可讓您加密 AWS AppConfig 託管組態存放區中的新組態資料版本。如需此金鑰的詳細資訊，請參閱 中的**AWS AppConfig 支援客戶管理員金鑰**[中的安全性 AWS AppConfig](appconfig-security.md)。

   1. 在**標籤**區段中，選擇**新增標籤**，然後指定金鑰和選用值。

1. 選擇**下一步**。

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

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

1. （選用） 展開**描述**並輸入此標記的相關資訊。

1. 選取 **這是短期旗標**，並選擇性地選擇應該停用或刪除旗標的日期。 AWS AppConfig *不會*在棄用日期停用旗標。

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. 在**檢閱和儲存**頁面上，驗證旗標的詳細資訊，然後**儲存並繼續部署**。

繼續執行「[在 中部署功能旗標和組態資料 AWS AppConfig](deploying-feature-flags.md)」。

# 建立特徵標記組態描述檔 （命令列）
<a name="appconfig-creating-feature-flag-configuration-commandline"></a>

下列程序說明如何使用 AWS Command Line Interface （在 Linux 或 Windows 上） 或 Tools for Windows PowerShell 來建立 AWS AppConfig 功能旗標組態描述檔。在建立組態設定檔時，您也可以建立基本功能旗標。

**建立功能旗標組態**

1. 開啟 AWS CLI。

1. 建立特徵標記組態描述檔，將其**類型**指定為 `AWS.AppConfig.FeatureFlags`。組態設定檔必須使用 `hosted`做為位置 URI。

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

   ```
   aws appconfig create-configuration-profile \
     --application-id APPLICATION_ID \
     --name CONFIGURATION_PROFILE_NAME \
     --location-uri hosted \
     --type AWS.AppConfig.FeatureFlags
   ```

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

   ```
   aws appconfig create-configuration-profile ^
     --application-id APPLICATION_ID ^
     --name CONFIGURATION_PROFILE_NAME ^
     --location-uri hosted ^
     --type AWS.AppConfig.FeatureFlags
   ```

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

   ```
   New-APPCConfigurationProfile `
     -Name CONFIGURATION_PROFILE_NAME `
     -ApplicationId APPLICATION_ID `
     -LocationUri hosted `
     -Type AWS.AppConfig.FeatureFlags
   ```

------

1. 建立您的特徵標記組態資料。您的資料必須採用 JSON 格式並符合 `AWS.AppConfig.FeatureFlags` JSON 結構描述。如需結構描述的詳細資訊，請參閱 [了解 的類型參考 AWS.AppConfig.FeatureFlags](appconfig-type-reference-feature-flags.md)。

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
   ```

------
#### [ 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
   ```

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

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

------

   命令會從磁碟載入為 `Content` 參數指定的內容。內容必須與下列範例類似。

   ```
   {
       "flags": {
           "ui_refresh": {
               "name": "UI Refresh"
           }
       },
       "values": {
           "ui_refresh": {
               "enabled": false,
               "attributeValues": {
                   "dark_mode_support": true
               }
           }
       },
       "version": "1"
   }
   ```

   系統會傳回如下資訊。

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

   ```
   {
      "ApplicationId"          : "ui_refresh",
      "ConfigurationProfileId" : "UI Refresh",
      "VersionNumber"          : "1",
      "ContentType"            : "application/json"
   }
   ```

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

   ```
   {
      "ApplicationId"          : "ui_refresh",
      "ConfigurationProfileId" : "UI Refresh",
      "VersionNumber"          : "1",
      "ContentType"            : "application/json"
   }
   ```

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

   ```
   ApplicationId          : ui_refresh
   ConfigurationProfileId : UI Refresh
   VersionNumber          : 1
   ContentType            : application/json
   ```

------

   `service_returned_content_file` 包含您的組態資料，其中包含一些 AWS AppConfig 產生的中繼資料。
**注意**  
當您建立託管組態版本時， 會 AWS AppConfig 驗證您的資料是否符合 `AWS.AppConfig.FeatureFlags` JSON 結構描述。 AWS AppConfig 還會驗證資料中的每個特徵標記屬性是否符合您為這些屬性定義的限制。

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

特徵標記變體可讓您定義一組可能的標記值，以針對請求傳回。您也可以為多變量旗標設定不同的狀態 （啟用或停用）。請求使用變體設定的旗標時，您的應用程式會提供根據一組使用者定義規則 AWS AppConfig 進行評估的內容。根據請求中指定的內容和為變體定義的規則， 會 AWS AppConfig 傳回不同的旗標值給應用程式。

下列螢幕擷取畫面顯示具有三個使用者定義變體和預設變體的功能標記範例。

![\[具有變體的功能旗標範例螢幕擷取畫面。\]](http://docs.aws.amazon.com/zh_tw/appconfig/latest/userguide/images/flag-variant-example.png)


**Topics**
+ [

# 了解多變體特徵標記概念和常見使用案例
](appconfig-creating-multi-variant-feature-flags-concepts.md)
+ [

# 了解多變體特徵標記規則
](appconfig-creating-multi-variant-feature-flags-rules.md)
+ [

# 建立多變體功能旗標
](appconfig-creating-multi-variant-feature-flags-procedures.md)

# 了解多變體特徵標記概念和常見使用案例
<a name="appconfig-creating-multi-variant-feature-flags-concepts"></a>

為了協助您進一步了解特徵標記變體，本節說明標記變體概念和常見使用案例。

**概念**
+ **特徵標記**：用於控制應用程式中特徵行為的 AWS AppConfig 組態類型。旗標具有狀態 （啟用或停用），以及包含任意字串、數值、布林值或陣列值的選用屬性集。
+ **特徵標記變體**：屬於特徵標記的狀態和屬性值的特定組合。特徵標記可能有多個變體。
+ **變體規則**：用於選取特徵標記變體的使用者定義表達式。每個變體都有自己的規則來 AWS AppConfig 評估 ，以判斷是否要傳回它。
+ **預設變體**：未選取其他變體時傳回的特殊變體。所有多變體功能旗標都有預設變體。

  請注意，預設變體必須是您的變體順序中的最後一個變體，而且不能有與其相關聯的規則。如果最後未定義，當您嘗試建立多變數旗標`BadRequestException`時， 會 AWS AppConfig 傳回 。
+ **內容**： AWS AppConfig 在組態擷取時間傳遞給 的使用者定義金鑰和值。在規則評估期間，會使用內容值來選取要傳回的功能標記變體。

**注意**  
AWS AppConfig 代理程式會評估變體規則，並根據提供的內容判斷哪些規則適用於請求。如需擷取多變體功能旗標的詳細資訊，請參閱 [擷取基本和多變體功能旗標](appconfig-integration-retrieving-feature-flags.md)。

**常見使用案例**

本節說明特徵標記變體的兩個常見使用案例。

*使用者分段*

使用者分割是根據特定屬性分割使用者的程序。例如，您可以使用標記變體，根據使用者 ID、地理位置、裝置類型或購買頻率，將功能公開給某些使用者，而不是其他使用者。

使用購買頻率的範例，假設您的商業應用程式支援提高客戶忠誠度的功能。您可以使用旗標變體來設定要根據使用者上次購買某物的時間，向他們顯示的不同獎勵類型。新使用者可能會獲得小折扣，以鼓勵他們成為客戶，而如果重複的客戶從新類別購買商品，可能會獲得更大的折扣。

*流量分割*

流量分割是根據您定義的內容值選取隨機但一致的標記變體的程序。例如，您可能想要執行實驗，其中一小部分的 使用者 （以其使用者 ID 識別） 會看到特定變體。或者，您可能想要執行漸進式特徵推展，其中特徵首先公開到 5% 的使用者，然後是 15%，然後是 40%，然後是 100%，同時在整個推展過程中保持一致的使用者體驗。

使用實驗範例，您可以使用標記變體來測試應用程式首頁上主要動作的新按鈕樣式，以查看它是否驅動更多點擊。針對您的實驗，您可以使用流量分割規則建立標記變體，該規則會選取 5% 的使用者來查看新樣式，而預設變體會指出應該繼續查看現有樣式的使用者。如果實驗成功，您可以增加百分比值，甚至將該變體轉換為預設值。

# 了解多變體特徵標記規則
<a name="appconfig-creating-multi-variant-feature-flags-rules"></a>

當您建立特徵標記變體時，您可以為其指定規則。規則是將內容值作為輸入並產生布林值結果作為輸出的表達式。例如，您可以定義規則，為 Beta 使用者選取標記變體，並以其帳戶 ID 識別，以測試使用者介面重新整理。在此案例中，您可以執行下列動作：

1. 建立新的特徵標記組態設定檔，稱為 *UI Refresh*。

1. 建立名為 *ui\$1refresh* 的新功能旗標。

1. 在建立特徵標記之後對其進行編輯，以新增變體。

1. 建立並啟用名為 *BetaUsers* 的新變體。

1. 定義 *BetaUsers* 規則，如果請求內容中的帳戶 ID 位於核准檢視新 Beta 體驗的帳戶 IDs 清單中，則會選取變體。

1. 確認預設變體的狀態設定為**已停用**。

**注意**  
變體會根據在主控台中定義的順序，評估為排序清單。首先評估清單頂端的變體。如果沒有規則符合提供的內容， 會 AWS AppConfig 傳回預設變體。

當 AWS AppConfig 處理特徵標記請求時，它會先比較提供的內容，其中包括 AccountID （在此範例中為 ) 與 BetaUsers 變體。如果內容符合 BetaUsers 的規則， 會 AWS AppConfig 傳回 Beta 體驗的組態資料。如果內容不包含帳戶 ID，或帳戶 ID 結尾不是 123， 會 AWS AppConfig 傳回預設規則的組態資料，這表示使用者檢視目前的生產體驗。

**注意**  
如需擷取多變體功能旗標的資訊，請參閱 [擷取基本和多變體功能旗標](appconfig-integration-retrieving-feature-flags.md)。

# 定義多變體特徵標記的規則
<a name="appconfig-creating-multi-variant-feature-flags-rules-operators"></a>

變體規則是由一或多個運算元和 運算子組成的表達式。運算元是在評估規則期間使用的特定值。運算元值可以是靜態的，例如常值或字串，或變數，例如在內容中找到的值，或另一個表達式的結果。運算子，例如「大於」，是套用至其運算元並產生值的測試或動作。變體規則表達式必須產生「true」或「false」才有效。

**運算元**


****  

| Type | 說明 | 範例 | 
| --- | --- | --- | 
|  String  |  UTF-8 字元的序列，以雙引號括住。  |  <pre>"apple", "Ḽơᶉëᶆ ȋṕšᶙṁ"</pre>  | 
|  Integer  |  64 位元整數值。  |  <pre>-7, 42 </pre>  | 
|  Float  |  64 位元 IEEE-754 浮點值。  |  <pre>3.14, 1.234e-5</pre>  | 
|  時間戳記  |  W[W3C 日期和時間格式](https://www.w3.org/TR/NOTE-datetime)所述的特定時間點。  |  <pre>2012-03-04T05:06:07-08:00, 2024-01</pre>  | 
|  Boolean  |  true 或 false 值。  |  <pre>true, false</pre>  | 
|  內容值  |  規則評估期間從內容擷取的 \$1*key* 格式參數化值。  |  <pre>$country, $userId</pre>  | 

**比較運算子**


****  

| 運算子 | Description | 範例 | 
| --- | --- | --- | 
|  eq  |  決定內容值是否等於指定的值。  |  <pre>(eq $state "Virginia")</pre>  | 
|  gt  |  決定內容值是否大於指定的值。  |  <pre>(gt $age 65)</pre>  | 
|  gte  |  決定內容值是否大於或等於指定的值。  |  <pre>(gte $age 65)</pre>  | 
|  lt  |  決定內容值是否小於指定的值。  |  <pre>(lt $age 65)</pre>  | 
|  lte  |  決定內容值是否小於或等於指定值。  |  <pre>(lte $age 65)</pre>  | 

**邏輯運算子**


****  

| 運算子 | Description | 範例 | 
| --- | --- | --- | 
|  及  |  判斷兩個運算元是否為 true。  |  <pre>(and <br />    (eq $state "Virginia") <br />    (gt $age 65)<br />)</pre>  | 
|  或  |  判斷至少一個運算元是否為 true。  |  <pre>(or<br />    (eq $state "Virginia") <br />    (gt $age 65)<br />)</pre>  | 
|  非  |  反轉表達式的值。  |  <pre>(not (eq $state "Virginia"))</pre>  | 

**自訂運算子**


****  

| 運算子 | Description | 範例 | 
| --- | --- | --- | 
|  start\$1with  |  決定內容值是否以指定的字首開頭。  |  <pre>(begins_with $state "A")</pre>  | 
|  end\$1with  |  決定內容值是否以指定的字首結尾。  |  <pre>(ends_with $email "amazon.com")</pre>  | 
|  contains  |  決定內容值是否包含指定的子字串。  |  <pre>(contains $promoCode "WIN")</pre>  | 
|  in  |  決定內容值是否包含在常數清單中。  |  <pre>(in $userId ["123", "456"])</pre>  | 
|  相符項目  |  決定內容值是否符合指定的 regex 模式。  |  <pre>(matches in::$greeting pattern::"h.*y")</pre>  | 
|  exists  |  決定是否為內容索引鍵提供任何值。  |  <pre>(exists key::"country")</pre>  | 
|  分割  |  根據所提供內容值的一致性雜湊，`true`評估給 （指定百分比） 的流量。如需如何`split`運作的詳細說明，請參閱本主題的下一節：[了解分割運算子](appconfig-creating-multi-variant-feature-flags-rules.md#appconfig-creating-multi-variant-feature-flags-rules-operators-split)。 請注意， `seed` 是選用的 屬性。如果您不指定 `seed`，雜湊會在*本機*一致，這表示該旗標的流量會一致分割，但接收相同內容值的其他旗標可能會以不同方式分割流量。如果`seed`提供 ，則保證每個唯一值在特徵標記、組態描述檔和 之間一致地分割流量 AWS 帳戶。  |  <pre>(split pct::10 by::$userId seed::"abc")</pre>  | 

## 了解分割運算子
<a name="appconfig-creating-multi-variant-feature-flags-rules-operators-split"></a>

下一節說明 `split`運算子在不同案例中使用時的行為。提醒您， 會根據所提供內容值的一致雜湊，`split`評估給 `true`的指定流量百分比。為了更清楚這一點，請考慮以下使用分割搭配兩個變體的基準案例：

```
A: (split by::$uniqueId pct::20)
C: <no rule>
```

如預期，提供隨機`uniqueId`的值集會產生大約如下的分佈：

```
A: 20%
C: 80%
```

如果您新增第三個變體，但使用相同的分割百分比，如下所示：

```
A: (split by::$uniqueId pct::20)
B: (split by::$uniqueId pct::20)
C: <default>
```

最後，您會使用下列分佈：

```
A: 20%
B: 0%
C: 80%
```

由於每個變體規則會依序評估，且第一個相符項目會決定傳回的變體，因此可能會發生此潛在非預期的分佈。評估規則 A 時，20% `uniqueId`的值會相符，因此會傳回第一個變體。接著，評估規則 B。不過，`uniqueId`變體規則 A 已比對所有符合第二個分割陳述式的值，因此沒有符合 B 的值。會改為傳回預設變體。

現在請考慮第三個範例。

```
A: (split by::$uniqueId pct::20)
B: (split by::$uniqueId pct::25)
C: <default>
```

與上一個範例一樣，前 20% `uniqueId`的值符合規則 A。對於變體規則 B，所有`uniqueId`值的 25% 會符合，但先前符合的大部分規則 A。這會留下變體 B 總數的 5%，其餘接收變體 C。分佈看起來如下：

```
A: 20%
B: 5%
C: 75%
```

**使用 `seed` 屬性**  
您可以使用 `seed` 屬性來確保指定內容值的流量一致分割，無論分割運算子在何處使用。如果您不指定 `seed`，雜湊會在*本機*一致，這表示該旗標的流量會一致分割，但接收相同內容值的其他旗標可能會以不同方式分割流量。如果`seed`提供 ，則保證每個唯一值在特徵標記、組態描述檔和 之間一致地分割流量 AWS 帳戶。

一般而言，客戶在分割相同內容屬性上的流量時，會在旗標內的變體間使用相同的`seed`值。不過，有時使用不同的種子值是合理的。以下是針對規則 A 和 B 使用不同種子的範例：

```
A: (split by::$uniqueId pct::20 seed::"seed_one")
B: (split by::$uniqueId pct::25 seed::"seed_two")
C: <default>
```

與之前一樣，20% 的相符`uniqueId`值符合規則 A。這表示 80% 的值會通過，並根據變體規則 B 進行測試。由於種子不同，相符 A 的值與相符 B 的值之間沒有關聯。不過，只有 80% `uniqueId`的值要分割為該數字相符規則 B 的 25%，而沒有 75%。這適用於下列分佈：

```
A: 20%
B: 20% (25% of what falls through from A, or 25% of 80%) 
C: 60%
```

# 建立多變體功能旗標
<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 此外， 會驗證資料中的每個特徵標記屬性是否符合您為這些屬性定義的限制。

# 了解 的類型參考 AWS.AppConfig.FeatureFlags
<a name="appconfig-type-reference-feature-flags"></a>

使用 `AWS.AppConfig.FeatureFlags` JSON 結構描述做為建立特徵標記組態資料的參考。

```
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "flagSetDefinition": {
      "type": "object",
      "properties": {
        "version": {
          "$ref": "#/definitions/flagSchemaVersions"
        },
        "flags": {
          "$ref": "#/definitions/flagDefinitions"
        },
        "values": {
          "$ref": "#/definitions/flagValues"
        }
      },
      "required": ["version"],
      "additionalProperties": false
    },
    "flagDefinitions": {
      "type": "object",
      "patternProperties": {
        "^[a-z][a-zA-Z\\d_-]{0,63}$": {
          "$ref": "#/definitions/flagDefinition"
        }
      },
      "additionalProperties": false
    },
    "flagDefinition": {
      "type": "object",
      "properties": {
        "name": {
          "$ref": "#/definitions/customerDefinedName"
        },
        "description": {
          "$ref": "#/definitions/customerDefinedDescription"
        },
        "_createdAt": {
          "type": "string"
        },
        "_updatedAt": {
          "type": "string"
        },
        "_deprecation": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string",
              "enum": ["planned"]
            },
            "date": {
              "type": "string",
              "format": "date"
            }
          },
         "additionalProperties": false
        },
        "attributes": {
          "$ref": "#/definitions/attributeDefinitions"
        }
      },
      "additionalProperties": false
    },
    "attributeDefinitions": {
      "type": "object",
      "patternProperties": {
        "^[a-z][a-zA-Z\\d_-]{0,63}$": {
          "$ref": "#/definitions/attributeDefinition"
        }
      },
      "maxProperties": 25,
      "additionalProperties": false
    },
    "attributeDefinition": {
      "type": "object",
      "properties": {
        "description": {
          "$ref": "#/definitions/customerDefinedDescription"
        },
        "constraints": {
          "oneOf": [
            { "$ref": "#/definitions/numberConstraints" },
            { "$ref": "#/definitions/stringConstraints" },
            { "$ref": "#/definitions/arrayConstraints" },
            { "$ref": "#/definitions/boolConstraints" }
          ]
        }
      },
      "additionalProperties": false
    },
    "flagValues": {
      "type": "object",
      "patternProperties": {
        "^[a-z][a-zA-Z\\d_-]{0,63}$": {
          "$ref": "#/definitions/flagValue"
        }
      },
      "additionalProperties": false
    },
    "flagValue": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "_createdAt": {
          "type": "string"
        },
        "_updatedAt": {
          "type": "string"
        },
        "_variants": {
          "type": "array",
          "maxLength": 32,
          "items": {
            "$ref": "#/definitions/variant"
          }
        }
      },
      "patternProperties": {
        "^[a-z][a-zA-Z\\d_-]{0,63}$": {
          "$ref": "#/definitions/attributeValue",
          "maxProperties": 25
        }
      },
      "additionalProperties": false
    },
    "attributeValue": {
      "oneOf": [
        { "type": "string", "maxLength": 1024 },
        { "type": "number" },
        { "type": "boolean" },
        {
          "type": "array",
          "oneOf": [
            {
              "items": {
                "type": "string",
                "maxLength": 1024
              }
            },
            {
              "items": {
                "type": "number"
              }
            }
          ]
        }
      ],
      "additionalProperties": false
    },
    "stringConstraints": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["string"]
        },
        "required": {
          "type": "boolean"
        },
        "pattern": {
          "type": "string",
          "maxLength": 1024
        },
        "enum": {
          "type": "array",
          "maxLength": 100,
          "items": {
            "oneOf": [
              {
                "type": "string",
                "maxLength": 1024
              },
              {
                "type": "integer"
              }
            ]
          }
        }
      },
      "required": ["type"],
      "not": {
        "required": ["pattern", "enum"]
      },
      "additionalProperties": false
    },
    "numberConstraints": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["number"]
        },
        "required": {
          "type": "boolean"
        },
        "minimum": {
          "type": "integer"
        },
        "maximum": {
          "type": "integer"
        }
      },
      "required": ["type"],
      "additionalProperties": false
    },
    "arrayConstraints": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["array"]
        },
        "required": {
          "type": "boolean"
        },
        "elements": {
          "$ref": "#/definitions/elementConstraints"
        }
      },
      "required": ["type"],
      "additionalProperties": false
    },
    "boolConstraints": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["boolean"]
        },
        "required": {
          "type": "boolean"
        }
      },
      "required": ["type"],
      "additionalProperties": false
    },
    "elementConstraints": {
      "oneOf": [
        { "$ref": "#/definitions/numberConstraints" },
        { "$ref": "#/definitions/stringConstraints" }
      ]
    },
    "variant": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "name": {
          "$ref": "#/definitions/customerDefinedName"
        },
        "rule": {
          "type": "string",
          "maxLength": 16384
        },
        "attributeValues": {
          "type": "object", 
          "patternProperties": {
            "^[a-z][a-zA-Z\\d_-]{0,63}$": {
              "$ref": "#/definitions/attributeValue"
            }
          },
          "maxProperties": 25,
          "additionalProperties": false
        }
      },
      "required": ["name", "enabled"],
      "additionalProperties": false
    },
    "customerDefinedName": {
      "type": "string",
      "pattern": "^[^\\n]{1,64}$"
    },
    "customerDefinedDescription": {
      "type": "string",
      "maxLength": 1024
    },
    "flagSchemaVersions": {
      "type": "string",
      "enum": ["1"]
    }
  },
  "type": "object",
  "$ref": "#/definitions/flagSetDefinition",
  "additionalProperties": false
}
```

**重要**  
若要擷取特徵標記組態資料，您的應用程式必須呼叫 `GetLatestConfiguration` API。您無法透過呼叫已棄用的 `GetConfiguration`來擷取特徵標記組態資料。如需詳細資訊，請參閱《 *AWS AppConfig API 參考*》中的 [GetLatestConfiguration](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_GetLatestConfiguration.html)。

當您的應用程式呼叫 [GetLatestConfiguration](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_GetLatestConfiguration.html) 並收到新部署的組態時，會移除定義功能旗標和屬性的資訊。簡化的 JSON 包含符合您指定之每個旗標索引鍵的索引鍵映射。簡化的 JSON 也包含 `false` `enabled` 屬性的 `true`或 對應值。如果旗標`enabled`設定為 `true`，則旗標的任何屬性也會存在。下列 JSON 結構描述描述 JSON 輸出的格式。

```
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "patternProperties": {
    "^[a-z][a-zA-Z\\d_-]{0,63}$": {
      "$ref": "#/definitions/attributeValuesMap"
    }
  },
  "additionalProperties": false,
  "definitions": {
    "attributeValuesMap": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        }
      },
      "required": ["enabled"],
      "patternProperties": {
        "^[a-z][a-zA-Z\\d_-]{0,63}$": {
          "$ref": "#/definitions/attributeValue"
        }
      },
      "maxProperties": 25,
      "additionalProperties": false
    },
    "attributeValue": {
      "oneOf": [
        { "type": "string","maxLength": 1024 },
        { "type": "number" },
        { "type": "boolean" },
        {
          "type": "array",
          "oneOf": [
            {
              "items": {
                "oneOf": [
                  {
                    "type": "string",
                    "maxLength": 1024
                  }
                ]
              }
            },
            {
              "items": {
                "oneOf": [
                  {
                    "type": "number"
                  }
                ]
              }
            }
          ]
        }
      ],
      "additionalProperties": false
    }
  }
}
```

# 將先前的特徵標記版本儲存到新版本
<a name="appconfig-creating-configuration-profile-feature-flags-editing-version"></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. 選擇**開始部署**以部署新版本。

# 在 中建立自由格式組態描述檔 AWS AppConfig
<a name="appconfig-free-form-configurations-creating"></a>

*組態資料*是影響應用程式行為的設定集合。*組態描述*檔包含一個 URI，該 URI AWS AppConfig 可讓 將組態資料定位在其儲存的位置和組態類型。使用自由格式組態設定檔，您可以將資料存放在 AWS AppConfig 託管組態存放區，或以下任何 AWS 服務 和 Systems Manager 工具：


****  

| Location | 支援的檔案類型 | 
| --- | --- | 
|  AWS AppConfig 託管組態存放區  |  如果使用 新增 YAML、JSON 和文字 AWS 管理主控台。使用 AWS AppConfig [CreateHostedConfigurationVersion](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_CreateHostedConfigurationVersion.html) API 動作新增的任何檔案類型。  | 
|  [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)  |  任何  | 
|  [AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html)  |  管道 （由 服務定義）  | 
|  [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html)  |  秘密 （由 服務定義）  | 
|  [AWS Systems Manager 參數存放區](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)  |  標準且安全的字串參數 （如參數存放區所定義）  | 
|  [AWS Systems Manager 文件存放區 (SSM 文件）](https://docs.aws.amazon.com/systems-manager/latest/userguide/documents.html)  |  YAML、JSON、文字  | 

組態描述檔也可以包含選用的驗證程式，以確保您的組態資料在語法和語義上正確。當您啟動部署時， 會使用驗證程式 AWS AppConfig 執行檢查。如果偵測到任何錯誤，部署會在對組態的目標進行任何變更之前停止。

**注意**  
如果可能，我們建議您在 AWS AppConfig 託管組態存放區中託管您的組態資料，因為它提供最多的功能和增強功能。

對於存放在 AWS AppConfig 託管組態存放區或 SSM 文件中的自由格式組態，您可以在建立組態設定檔時使用 Systems Manager 主控台來建立自由格式組態。本主題稍後將說明此程序。

對於儲存在參數存放區、Secrets Manager 或 Amazon S3 中的自由格式組態，您必須先建立參數、秘密或物件，並將其存放在相關的組態存放區中。儲存組態資料之後，請使用本主題中的程序來建立組態設定檔。

**Topics**
+ [

# 了解驗證程式
](appconfig-creating-configuration-and-profile-validators.md)
+ [

# 了解組態存放區配額和限制
](appconfig-creating-configuration-and-profile-quotas.md)
+ [

# 了解 AWS AppConfig 託管組態存放區
](appconfig-creating-configuration-and-profile-about-hosted-store.md)
+ [

# 了解存放在 Amazon S3 中的組態
](appconfig-creating-configuration-and-profile-S3-source.md)
+ [

# 建立 AWS AppConfig 自由格式組態描述檔 （主控台）
](appconfig-creating-free-form-configuration-and-profile-create-console.md)
+ [

# 建立 AWS AppConfig 自由格式組態描述檔 （命令列）
](appconfig-creating-free-form-configuration-and-profile-create-commandline.md)

# 了解驗證程式
<a name="appconfig-creating-configuration-and-profile-validators"></a>

當您建立組態描述檔時，您可以選擇指定最多兩個驗證程式。驗證器可確保您的組態資料在語法和語義上是正確的。如果您計劃使用驗證程式，您必須先建立它，才能建立組態描述檔。 AWS AppConfig 支援下列類型的驗證程式：
+ **AWS Lambda 函數**：支援特徵標記和自由格式組態。
+ **JSON 結構描述**：支援自由格式組態。（針對 JSON 結構描述AWS AppConfig 自動驗證功能旗標。)

**Topics**
+ [

## AWS Lambda 函數驗證程式
](#appconfig-creating-configuration-and-profile-validators-lambda)
+ [

## JSON 結構描述驗證程式
](#appconfig-creating-configuration-and-profile-validators-json-schema)

## AWS Lambda 函數驗證程式
<a name="appconfig-creating-configuration-and-profile-validators-lambda"></a>

Lambda 函數驗證程式必須使用下列事件結構描述進行設定。 AWS AppConfig 使用此結構描述來叫用 Lambda 函數。內容是一個 base64 編碼的字串，而 URI 是字串。

```
{
    "applicationId": "The application ID of the configuration profile being validated", 
    "configurationProfileId": "The ID of the configuration profile being validated",
    "configurationVersion": "The version of the configuration profile being validated",
    "content": "Base64EncodedByteString", 
    "uri": "The configuration uri"    
}
```

AWS AppConfig 驗證 Lambda `X-Amz-Function-Error`標頭是否已在回應中設定。如果函數擲回例外狀況，Lambda 會設定此標頭。如需 的詳細資訊`X-Amz-Function-Error`，請參閱《 *AWS Lambda 開發人員指南*》[中的錯誤處理和自動重試 AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/retries-on-errors.html)。

以下是成功驗證的 Lambda 回應程式碼簡單範例。

```
import json

def handler(event, context):
     #Add your validation logic here
     print("We passed!")
```

以下是失敗驗證的 Lambda 回應程式碼簡單範例。

```
def handler(event, context):
     #Add your validation logic here
     raise Exception("Failure!")
```

這是另一個只有在組態參數為質數時才會驗證的例子。

```
function isPrime(value) {
    if (value < 2) {
        return false;
    }

    for (i = 2; i < value; i++) {
        if (value % i === 0) {
            return false;
        }
    }

    return true;
}

exports.handler = async function(event, context) {
    console.log('EVENT: ' + JSON.stringify(event, null, 2));
    const input = parseInt(Buffer.from(event.content, 'base64').toString('ascii'));
    const prime = isPrime(input);
    console.log('RESULT: ' + input + (prime ? ' is' : ' is not') + ' prime');
    if (!prime) {
        throw input + "is not prime";
    }
}
```

AWS AppConfig 會在呼叫 `StartDeployment`和 `ValidateConfigurationActivity` API 操作時呼叫您的驗證 Lambda。您必須提供叫用 Lambda 的`appconfig.amazonaws.com`許可。如需詳細資訊，請參閱[授予函數存取 AWS Services](https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html#permissions-resource-serviceinvoke)。將驗證 Lambda 執行時間 AWS AppConfig 限制為 15 秒，包括啟動延遲。

## JSON 結構描述驗證程式
<a name="appconfig-creating-configuration-and-profile-validators-json-schema"></a>

如果您在 SSM 文件中建立組態，則必須指定或建立該組態的 JSON 結構描述。JSON 結構描述可定義每個應用程式組態設定的允許屬性。JSON 結構描述的功能就像一組規則，以確保新的或更新後的組態設定符合您應用程式所需的最佳實務。請見此處範例。

```
    {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "title": "$id$",
      "description": "BasicFeatureToggle-1",
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
          "[^\\s]+$": {
              "type": "boolean"
          }
      },
      "minProperties": 1
    }
```

當您從 SSM 文件建立組態時，系統會自動驗證組態是否符合結構描述要求。如果不符合， AWS AppConfig 會傳回驗證錯誤。

**重要**  
請注意下列有關 JSON 結構描述驗證程式的重要資訊：  
儲存在 SSM 文件中的組態資料必須先對相關的 JSON 結構描述進行驗證，才能將組態新增至系統。SSM 參數不需要驗證方法，但建議您使用 為新的或更新的 SSM 參數組態建立驗證檢查 AWS Lambda。
SSM 文件中的組態會使用 `ApplicationConfiguration` 文件類型。對應的 JSON 結構描述使用 `ApplicationConfigurationSchema` 文件類型。
AWS AppConfig 支援 JSON 結構描述 4.X 版的內嵌結構描述。如果您的應用程式組態需要不同版本的 JSON 結構描述，則必須建立 Lambda 驗證程式。

# 了解組態存放區配額和限制
<a name="appconfig-creating-configuration-and-profile-quotas"></a>

支援的組態存放區 AWS AppConfig 具有下列配額和限制。


****  

|  | AWS AppConfig 託管組態存放區 | Amazon S3 | Systems Manager Parameter Store | AWS Secrets Manager | Systems Manager 文件存放區 | AWS CodePipeline | 
| --- | --- | --- | --- | --- | --- | --- | 
|  **組態大小限制**  | 預設 2 MB，最多 4 MB |  2 MB 強制執行者 AWS AppConfig，而非 S3  |  4 KB (免費方案)/8 KB (進階參數)  | 64 KB |  64 KB  | 2 MB強制執行者 AWS AppConfig，而非 CodePipeline | 
|  **資源儲存限制**  | 1 GB |  無限制  |  10,000 個參數 (免費方案)/100,000 個參數 (進階參數)  | 500,000 |  500 份文件  | 受限於每個應用程式的組態設定檔數量 （每個應用程式 100 個設定檔） | 
|  **伺服器端加密**  | 是 |  [SSE-S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/serv-side-encryption.html)、[SSE-KMS](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingKMSEncryption.html)  |  是  | 是 |  否  | 是 | 
|  **CloudFormation 支援**  | 是 |  不適用於建立或更新資料  |  是  | 是 |  否  | 是 | 
|  **定價**  | 免費 |  請參閱 [Amazon S3 定價](https://aws.amazon.com//s3/pricing/)  |  請參閱[AWS Systems Manager 定價](https://aws.amazon.com//systems-manager/pricing/)  | 請參閱[AWS Secrets Manager 定價](https://aws.amazon.com//secrets-manager/pricing/) |  免費  |  請參閱[AWS CodePipeline 定價](https://aws.amazon.com//codepipeline/pricing/)  | 

# 了解 AWS AppConfig 託管組態存放區
<a name="appconfig-creating-configuration-and-profile-about-hosted-store"></a>

AWS AppConfig 包含內部或託管組態存放區。組態必須為 2 MB 或更小。相較於其他組態存放區選項， AWS AppConfig 託管組態存放區提供下列優點。
+ 您不需要設定其他服務，例如 Amazon Simple Storage Service (Amazon S3) 或參數存放區。
+ 您不需要設定 AWS Identity and Access Management (IAM) 許可即可使用組態存放區。
+ 您可以將組態存放為 YAML、JSON 或文字文件。
+ 使用存放區無需付費。
+ 您可以建立組態，並在建立組態描述檔時將其新增至存放區。

# 了解存放在 Amazon S3 中的組態
<a name="appconfig-creating-configuration-and-profile-S3-source"></a>

您可以將組態存放在 Amazon Simple Storage Service (Amazon S3) 儲存貯體中。在您建立組態描述檔時，您可以指定指向儲存貯體中單一 S3 物件的 URI。您也可以指定 (IAM) 角色的 Amazon Resource Name AWS Identity and Access Management (ARN)，以授予 AWS AppConfig 取得物件的許可。為 Amazon S3 物件建立組態設定檔之前，請注意下列限制。


****  

| 限制 | 詳細資訊 | 
| --- | --- | 
|  大小  |  存放為 S3 物件的組態大小上限為 1 MB。  | 
|  物件加密  |  組態設定檔可以鎖定 SSE-S3 和 SSE-KMS 加密物件。  | 
|  儲存類別  |  AWS AppConfig 支援下列 S3 儲存類別：`STANDARD`、`INTELLIGENT_TIERING`、`STANDARD_IA`、 `REDUCED_REDUNDANCY`和 `ONEZONE_IA`。不支援下列類別：所有 S3 Glacier 類別 (`GLACIER` 和 `DEEP_ARCHIVE`)。  | 
|  版本控制  |  AWS AppConfig 要求 S3 物件使用版本控制。  | 

## 設定儲存為 Amazon S3 物件之組態的許可
<a name="appconfig-creating-configuration-and-profile-S3-source-permissions"></a>

當您為存放為 S3 物件的組態建立組態描述檔時，您必須為 IAM 角色指定 ARN，以授予取得物件的 AWS AppConfig 許可。角色必須包含下列許可。

存取 S3 物件的許可
+ s3:GetObject
+ s3:GetObjectVersion

列出 S3 儲存貯體的許可

s3:ListAllMyBuckets

存放物件的 S3 儲存貯體的存取許可
+ s3:GetBucketLocation
+ s3:GetBucketVersioning
+ s3:ListBucket
+ s3:ListBucketVersions

完成下列程序以建立角色， AWS AppConfig 讓 取得存放在 S3 物件中的組態。

**建立存取 S3 物件的 IAM 政策**  
使用下列程序建立 IAM 政策，讓 AWS AppConfig 取得存放在 S3 物件中的組態。

**建立用於存取 S3 物件的 IAM 政策**

1. 在 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 中開啟 IAM 主控台。

1. 在導覽窗格中，選擇 **Policies (政策)**，然後選擇 **Create policy (建立政策)**。

1. 在**建立政策**頁面上，選擇 **JSON** 標籤。

1. 使用 S3 儲存貯體及組態物件的相關資訊，更新以下範例政策。然後將政策貼入 **JSON** 標籤上的文字欄位中。使用您的資訊取代*預留位置的值*。

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "s3:GetObject",
           "s3:GetObjectVersion"
         ],
         "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/my-configurations/my-configuration.json"
       },
       {
         "Effect": "Allow",
         "Action": [
           "s3:GetBucketLocation",
           "s3:GetBucketVersioning",
           "s3:ListBucketVersions",
           "s3:ListBucket"
         ],
         "Resource": [
           "arn:aws:s3:::amzn-s3-demo-bucket"
         ]
       },
       {
         "Effect": "Allow",
         "Action": "s3:ListAllMyBuckets",
         "Resource": "*"
       } 
     ]
   }
   ```

------

1. 選擇**檢閱政策**。

1. 在 **Review policy (檢閱政策)** 頁面上，於 **Name (名稱)** 方塊中輸入名稱，然後輸入描述。

1. 選擇**建立政策**。系統會讓您回到 **Roles (角色)** 頁面。

**建立存取 S3 物件的 IAM 角色**  
使用下列程序建立 IAM 角色，讓 AWS AppConfig 取得存放在 S3 物件中的組態。

**建立用於存取 Amazon S3 物件的 IAM 角色**

1. 在以下網址開啟 IAM 主控台：[https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/)。

1. 在導覽窗格中，選擇**角色**，然後選擇**建立角色**。

1. 在**選取信任實體類型**區段中，選擇**AWS 服務**。

1. 在 **Choose a use case (選擇使用案例)** 區段中，選擇位於 **Common use cases (常見使用案例)** 下方的 **EC2**，然後選擇 **Next: Permissions (下一步：許可)**。

1. 在 **Attach permissions policy (連接許可政策)** 頁面上，於搜尋方塊中輸入您在上一個程序中建立的政策名稱。

1. 選擇政策，然後選擇 **Next: Tags (下一步：標籤)**。

1. 在**新增標籤 （選用）** 頁面上，輸入索引鍵和選用值，然後選擇**下一步：檢閱**。

1. 在 **Review (檢閱)** 頁面上，在 **Role name (角色名稱)** 欄位中輸入名稱，然後輸入描述。

1. 選擇 **Create role** (建立角色)。系統會讓您回到 **Roles (角色)** 頁面。

1. 在 **Roles (角色)** 頁面，選擇您剛建立的角色，以開啟 **Summary (摘要)** 頁面。請記下 **Role Name (角色名稱)** 和 **Role ARN (角色 ARN)**。您將會在本主題中稍後建立組態描述檔時指定角色 ARN。

**建立信任關係**  
使用下列程序來設定您剛建立的角色以信任 AWS AppConfig。

**新增信任關係**

1. 在您剛建立之角色的 **Summary (摘要)** 頁面中，選擇 **Trust Relationships (信任關係)** 索引標籤，然後著選擇 **Edit Trust Relationship (編輯信任關係)**。

1. 刪除 `"ec2.amazonaws.com"`，然後新增 `"appconfig.amazonaws.com"`，如以下範例所示。

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
           "Service": "appconfig.amazonaws.com"
         },
         "Action": "sts:AssumeRole"
       }
     ]
   }
   ```

------

1. 選擇 **Update Trust Policy** (更新信任政策)。

# 建立 AWS AppConfig 自由格式組態描述檔 （主控台）
<a name="appconfig-creating-free-form-configuration-and-profile-create-console"></a>

使用下列程序，透過 AWS Systems Manager 主控台建立 AWS AppConfig 自由格式組態設定檔和 （選擇性） 自由格式組態。

**建立自由格式組態描述檔**

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

1. 在導覽窗格中，選擇**應用程式**，然後選擇您在 中建立的應用程式[在 中為您的應用程式建立命名空間 AWS AppConfig](appconfig-creating-namespace.md)。

1. 選擇**組態設定檔和功能旗標**索引標籤，然後選擇**建立組態**。

1. 在**組態選項**區段中，選擇**自由格式組態**。

1. 在**組態設定檔名稱**中，輸入組態設定檔的名稱。

1. （選用） 展開**描述**並輸入描述。

1. （選用） 展開**其他選項**，並視需要完成下列操作。

   1. 在**關聯延伸**項目區段中，從清單中選擇延伸項目。

   1. 在**標籤**區段中，選擇**新增標籤**，然後指定金鑰和選用值。

1. 選擇**下一步**。

1. 在**指定組態資料**頁面上的**組態定義**區段中，選擇選項。

1. 完成您所選選項的欄位，如下表所述。  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/appconfig/latest/userguide/appconfig-creating-free-form-configuration-and-profile-create-console.html)

1. 在**服務角色**區段中，選擇**新增服務角色**，讓 AWS AppConfig 建立提供組態資料存取權的 IAM 角色。 會根據您先前輸入的名稱 AWS AppConfig 自動填入**角色名稱**欄位。或者，選擇**現有服務角色**。使用 **Role ARN (角色 ARN)** 清單選擇角色。

1. 或者，在**新增驗證程式**頁面上，選擇 **JSON 結構描述**或 **AWS Lambda**。如果您選擇 **JSON Schema (JSON 結構描述)**，請在欄位中輸入 JSON 結構描述。如果您選擇 **AWS Lambda**，請從清單中選擇 Amazon Resource Name (ARN) 和版本。
**重要**  
儲存在 SSM 文件中的組態資料必須先對相關的 JSON 結構描述進行驗證，才能將組態新增至系統。SSM 參數不需要驗證方法，但建議您使用 為新的或更新的 SSM 參數組態建立驗證檢查 AWS Lambda。

1. 選擇**下一步**。

1. 在**檢閱和儲存**頁面上，選擇**儲存並繼續部署**。

**重要**  
如果您為 建立組態設定檔 AWS CodePipeline，則必須在 CodePipeline 中建立管道，指定 AWS AppConfig 做為*部署提供者*。您不需要執行 [在 中部署功能旗標和組態資料 AWS AppConfig](deploying-feature-flags.md)。不過，您必須設定用戶端來接收應用程式組態更新，如中所述[在沒有 AWS AppConfig 代理程式的情況下擷取組態資料](about-data-plane.md)。如需建立指定 AWS AppConfig 做為部署提供者的管道的相關資訊，請參閱*AWS CodePipeline 《 使用者指南*》中的[教學課程：建立使用 AWS AppConfig 做為部署提供者的管道](https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-AppConfig.html)。

繼續執行「[在 中部署功能旗標和組態資料 AWS AppConfig](deploying-feature-flags.md)」。

# 建立 AWS AppConfig 自由格式組態描述檔 （命令列）
<a name="appconfig-creating-free-form-configuration-and-profile-create-commandline"></a>

下列程序說明如何使用 AWS CLI （在 Linux 或 Windows 上） 或 AWS Tools for PowerShell 來建立 AWS AppConfig 自由格式組態描述檔。如果您願意，您可以使用 AWS CloudShell 執行下列命令。如需詳細資訊，請參閱《 AWS CloudShell使用者指南**》中的[什麼是AWS CloudShell ？](https://docs.aws.amazon.com//cloudshell/latest/userguide/welcome.html)。

**注意**  
對於託管組態存放區中 AWS AppConfig 託管的自由格式組態，您可以`hosted`為位置 URI 指定 。

**使用 建立組態設定檔 AWS CLI**

1. 開啟 AWS CLI。

1. 執行下列命令來建立自由格式組態描述檔。

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

   ```
   aws appconfig create-configuration-profile \
     --application-id APPLICATION_ID \
     --name NAME \
     --description CONFIGURATION_PROFILE_DESCRIPTION \
     --location-uri CONFIGURATION_URI or hosted \
     --retrieval-role-arn IAM_ROLE_ARN \
     --tags TAGS \
     --validators "Content=SCHEMA_CONTENT or LAMBDA_FUNCTION_ARN,Type=JSON_SCHEMA or LAMBDA"
   ```

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

   ```
   aws appconfig create-configuration-profile ^
     --application-id APPLICATION_ID ^
     --name NAME ^
     --description CONFIGURATION_PROFILE_DESCRIPTION ^
     --location-uri CONFIGURATION_URI or hosted  ^
     --retrieval-role-arn IAM_ROLE_ARN ^
     --tags TAGS ^
     --validators "Content=SCHEMA_CONTENT or LAMBDA_FUNCTION_ARN,Type=JSON_SCHEMA or LAMBDA"
   ```

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

   ```
   New-APPCConfigurationProfile `
     -Name NAME `
     -ApplicationId APPLICATION_ID `
     -Description CONFIGURATION_PROFILE_DESCRIPTION `
     -LocationUri CONFIGURATION_URI or hosted `
     -RetrievalRoleArn IAM_ROLE_ARN `
     -Tag TAGS `
     -Validators "Content=SCHEMA_CONTENT or LAMBDA_FUNCTION_ARN,Type=JSON_SCHEMA or LAMBDA"
   ```

------

**重要**  
記下以下重要資訊。  
如果您為 建立組態設定檔 AWS CodePipeline，則必須在 CodePipeline 中建立管道，指定 AWS AppConfig 做為*部署提供者*。您不需要執行 [在 中部署功能旗標和組態資料 AWS AppConfig](deploying-feature-flags.md)。不過，您必須設定用戶端來接收應用程式組態更新，如中所述[在沒有 AWS AppConfig 代理程式的情況下擷取組態資料](about-data-plane.md)。如需建立指定 AWS AppConfig 做為部署提供者的管道的相關資訊，請參閱*AWS CodePipeline 《 使用者指南*》中的[教學課程：建立使用 AWS AppConfig 做為部署提供者的管道](https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-AppConfig.html)。
如果您在 AWS AppConfig 託管組態存放區中建立組態，您可以使用 [CreateHostedConfigurationVersion](https://docs.aws.amazon.com//appconfig/2019-10-09/APIReference/API_CreateHostedConfigurationVersion.html) API 操作來建立新的組態版本。若要檢視此 API 操作 AWS CLI 的詳細資訊和範例命令，請參閱《 *AWS CLI 命令參考*》中的 [create-hosted-configuration-version](https://docs.aws.amazon.com/cli/latest/reference/appconfig/create-hosted-configuration-version.html)。

繼續執行「[在 中部署功能旗標和組態資料 AWS AppConfig](deploying-feature-flags.md)」。

# 為非原生資料來源建立組態設定檔
<a name="appconfig-creating-configuration-profile-other-data-sources"></a>

AWS AppConfig 支援從大多數任何資料存放區部署組態資料。原生 AWS AppConfig 支援部署存放在下列服務中的組態資料：
+  AWS AppConfig 託管組態存放區
+ Amazon S3
+ AWS Secrets Manager
+ AWS Systems Manager 參數存放區
+ Systems Manager 文件存放區
+ AWS CodePipeline

如果您的組態資料存放在 原生不支援的位置 AWS AppConfig，您可以建立 [AWS AppConfig 擴充](https://docs.aws.amazon.com/appconfig/latest/userguide/working-with-appconfig-extensions.html)功能，從其來源擷取您的資料。例如，透過使用 AWS AppConfig 延伸模組，您可以擷取存放在 Amazon Relational Database Service (Amazon RDS)、Amazon DynamoDB (DynamoDB)、GitHub、GitLab 或本機儲存庫中的組態資料，例如一些。透過實作 擴充功能，您可以利用應用程式和運算環境 AWS AppConfig 的安全和 DevOps 增強功能。您也可以在將組態資料從舊版系統遷移到 時使用此方法 AWS AppConfig。

為 中 AWS AppConfig 原生不支援的資料來源建立組態描述檔涉及下列程序或動作：

1. 建立 [AWS Lambda 函數](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)，從資料來源擷取資料。只要 Lambda 函數可以存取資料來源，您的 AWS AppConfig 延伸模組就可以擷取資料。

1. 建立叫用 Lambda 函數的自訂 AWS AppConfig 延伸模組。如需詳細資訊，請參閱[逐步解說：建立自訂 AWS AppConfig 擴充功能](working-with-appconfig-extensions-creating-custom.md)。

1. 建立 AWS AppConfig 自由格式組態設定檔。具體而言，建立使用**AWS AppConfig 託管組態定義的組態**設定檔。組態設定檔會在 Lambda 函數從來源擷取您的組態之後，做為臨時資料存放區運作。您的應用程式會從 AWS AppConfig 託管組態存放區擷取組態資料。如需詳細資訊，請參閱[在 中建立自由格式組態描述檔 AWS AppConfig](appconfig-free-form-configurations-creating.md)。

1. 建立使用 `PRE_CREATE_HOSTED_CONFIGURATION_VERSION`動作點觸發的延伸關聯。如需詳細資訊，請參閱[步驟 4：建立自訂擴充功能的 AWS AppConfig 擴充功能關聯](working-with-appconfig-extensions-creating-custom-association.md)。

設定完成後，當您的應用程式請求新版本的組態資料時，Lambda 會擷取您的組態資料，並將其提取至組態描述檔。 AWS AppConfig 然後儲存組態描述檔和第三方資料。

當您準備好時，您可以將組態設定檔部署到您的應用程式，就像任何其他類型的組態資料一樣。

**注意**  
您可以選擇根據現有的組態資料插入第三方資料，或讓組態資料的完整內容僅包含第三方資料。如果您想要讓資料與其他現有資料一致，該邏輯應該是從第三方來源匯入資料之 Lambda 函數的一部分。

## AWS AppConfig 從舊版和自製組態服務遷移至
<a name="appconfig-creating-configuration-profile-other-data-sources-migrating"></a>

如果您已開始使用 ， AWS AppConfig 而且在另一個系統中仍有舊版組態資料或功能旗標，您可以使用本主題先前所述的程序，從舊版系統遷移到 AWS AppConfig。您可以建置延伸模組，從舊版系統提取資料並進行部署 AWS AppConfig。 AWS AppConfig 以這種方式使用 可為您提供所有安全護欄控制和優點，同時仍然使用舊版資料存放區。