

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

# 创建功能标志配置文件（命令行）
<a name="appconfig-creating-feature-flag-configuration-commandline"></a>

以下过程介绍如何使用 AWS Command Line Interface （在 Linux 或 Windows 上）或适用于 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 此外，还会验证数据中的每个要素标志属性是否满足您为这些属性定义的约束条件。