在中创建功能标志配置文件 Amazon AppConfig - Amazon AppConfig
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

在中创建功能标志配置文件 Amazon AppConfig

您可以使用功能标志来启用或禁用应用程序中的功能,也可以使用标志属性配置应用程序功能的不同特性。 Amazon AppConfig 以功能标志格式将功能标志配置存储在 Amazon AppConfig 托管配置存储中,该格式包含有关您的标志和旗帜属性的数据和元数据。有关 Amazon AppConfig 托管配置存储的更多信息,请参阅关于 Amazon AppConfig 托管配置存储第节。

创建功能标志和功能标志配置文件(控制台)

使用以下步骤使用 Amazon AppConfig 控制台创建 Amazon AppConfig 功能标志配置文件和功能标志配置。

创建配置文件
  1. 打开 Amazon Systems Manager 控制台,网址为 https://console.aws.amazon.com/systems-manager/appconfig/

  2. 应用程序选项卡上,选择您在创建Amazon AppConfig 配置中创建的应用程序,然后选择配置文件和功能标志选项卡。

  3. 选择创建

  4. 选择功能标志

创建功能标志
  1. 在您创建的配置上,选择添加新标志

  2. 提供标志名称 和(可选的)描述。通过在您提供的名称中用下划线替换空格,标志键会自动填充。如果需要不同的值或格式,可以编辑标志键。创建标志后,可以编辑标志名称,但不能编辑标志键。

  3. 使用切换按钮指定功能标志是启用还是禁用

  4. (可选)将属性属性约束添加到功能标志。属性使您能够在标志中提供其他值。您可以选择根据指定的约束来验证属性值。约束可确保不会将任何意外值部署到应用程序。

    Amazon AppConfig 功能标志支持以下类型的属性及其相应的约束。

    类型 约束 描述
    字符串 正则表达式

    字符串的正则表达式模式

    枚举

    字符串的可接受值列表

    数字 最低

    属性的最小数值

    最高

    属性的最大数值

    布尔值
    字符串数组 正则表达式 数组元素的正则表达式模式
    枚举 数组元素的可接受值列表
    数字数组 最低 数组元素的最小数值
    最高 数组元素的最大数值
    注意

    请注意以下信息。

    • 对于属性名称,保留了“启用”一词。无法创建名为“已启用”的功能标志属性。没有其他保留字。

    • 仅当启用了功能标志时,该标志的属性才包含在 GetLatestConfiguration 响应中。

    • 选择必需值以指定属性值是否为必需值。

  5. 选择保存新版本

继续执行在 Amazon AppConfig 中部署功能标志和配置数据

创建功能标志和功能标志配置文件(命令行)

以下过程介绍如何使用 Amazon Command Line Interface (在 Linux 或 Windows 上)或适用于 Windows 的工具 PowerShell 来创建 Amazon AppConfig 功能标志配置文件。如果您愿意,可以使用 Amazon CloudShell 运行下面列出的命令。有关更多信息,请参阅Amazon CloudShell 《用户指南》中的什么是 Amazon CloudShell?

分步创建特征标志配置
  1. 打开 Amazon CLI.

  2. 创建一个功能标志配置文件,将其类型指定为 AWS.AppConfig.FeatureFlags。配置文件必须使用 hosted 作为位置 URI。

    Linux
    aws appconfig create-configuration-profile \ --application-id The_application_ID \ --name A_name_for_the_configuration_profile \ --location-uri hosted \ --type AWS.AppConfig.FeatureFlags
    Windows
    aws appconfig create-configuration-profile ^ --application-id The_application_ID ^ --name A_name_for_the_configuration_profile ^ --location-uri hosted ^ --type AWS.AppConfig.FeatureFlags
    PowerShell
    New-APPCConfigurationProfile ` -Name A_name_for_the_configuration_profile ` -ApplicationId The_application_ID ` -LocationUri hosted ` -Type AWS.AppConfig.FeatureFlags
  3. 创建功能标志配置数据。您的数据必须采用 JSON 格式,并符合 AWS.AppConfig.FeatureFlags JSON 架构。有关架构的更多信息,请参阅 AWS.AppConfig.FeatureFlags 的类型引用

  4. 使用 CreateHostedConfigurationVersion API 将功能标志配置数据保存到 Amazon AppConfig。

    Linux
    aws appconfig create-hosted-configuration-version \ --application-id The_application_ID \ --configuration-profile-id The_configuration_profile_id \ --content-type "application/json" \ --content file://path/to/feature_flag_configuration_data \ file_name_for_system_to_store_configuration_data
    Windows
    aws appconfig create-hosted-configuration-version ^ --application-id The_application_ID ^ --configuration-profile-id The_configuration_profile_id ^ --content-type "application/json" ^ --content file://path/to/feature_flag_configuration_data ^ file_name_for_system_to_store_configuration_data
    PowerShell
    New-APPCHostedConfigurationVersion ` -ApplicationId The_application_ID ` -ConfigurationProfileId The_configuration_profile_id ` -ContentType "application/json" ` -Content file://path/to/feature_flag_configuration_data ` file_name_for_system_to_store_configuration_data

    下面是一个 Linux 示例命令。

    aws appconfig create-hosted-configuration-version \ --application-id 1a2b3cTestApp \ --configuration-profile-id 4d5e6fTestConfigProfile \ --content-type "application/json" \ --content Base64Content

    content 参数使用以下 base64 编码数据。

    { "flags": { "flagkey": { "name": "WinterSpecialBanner" } }, "values": { "flagkey": { "enabled": true } }, "version": "1" }

    系统将返回类似于以下内容的信息。

    Linux
    {
       "ApplicationId"          : "1a2b3cTestApp",
       "ConfigurationProfileId" : "4d5e6fTestConfigProfile",
       "VersionNumber"          : "1",
       "ContentType"            : "application/json"
    }
    Windows
    {
       "ApplicationId"          : "1a2b3cTestApp",
       "ConfigurationProfileId" : "4d5e6fTestConfigProfile",
       "VersionNumber"          : "1",
       "ContentType"            : "application/json"
    }
    PowerShell
    ApplicationId          : 1a2b3cTestApp
    ConfigurationProfileId : 4d5e6fTestConfigProfile
    VersionNumber          : 1
    ContentType            : application/json

    service_returned_content_file包含您的配置数据,其中包括一些 Amazon AppConfig 生成的元数据。

    注意

    创建托管配置版本时,请 Amazon AppConfig 验证您的数据是否符合 AWS.AppConfig.FeatureFlags JSON 架构。 Amazon AppConfig 此外,还会验证数据中的每个要素标志属性是否满足您为这些属性定义的约束条件。

AWS.AppConfig.FeatureFlags 的类型引用

使用 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", "flags"], "additionalProperties": false }, "flagDefinitions": { "type": "object", "patternProperties": { "^[a-z][a-zA-Z\\d-]{0,63}$": { "$ref": "#/definitions/flagDefinition" } }, "maxProperties": 100, "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"] } }, "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" } }, "maxProperties": 100, "additionalProperties": false }, "flagValue": { "type": "object", "properties": { "enabled": { "type": "boolean" }, "_createdAt": { "type": "string" }, "_updatedAt": { "type": "string" } }, "patternProperties": { "^[a-z][a-zA-Z\\d-_]{0,63}$": { "$ref": "#/definitions/attributeValue", "maxProperties": 25 } }, "required": ["enabled"], "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" } ] }, "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 来检索功能标志配置数据,该数据已弃用。有关更多信息,请参阅 Amazon AppConfig API 参考GetLatestConfiguration中的。

当您的应用程序调用GetLatestConfiguration并收到新部署的配置时,定义您的功能标志和属性的信息将被删除。简化的 JSON 包含与您指定的每个标志键匹配的键映射。简化的 JSON 还包含 enabled 属性的 truefalse 映射值。如果标志将 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" } }, "maxProperties": 100, "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 } } }