在中创建功能标志配置文件 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 Key Management Service (Amazon KMS) 密钥。此客户托管密钥使您能够加密 Amazon AppConfig 托管配置存储库中的新配置数据版本。有关此密钥的更多信息,请参阅中的Amazon AppConfig 支持客户经理密钥安全性 Amazon AppConfig

以下过程还为您提供了将扩展与功能标志配置文件关联的选项。在创建或部署配置 Amazon AppConfig 的工作流程中,扩展可以增强您在不同时刻注入逻辑或行为的能力。有关更多信息,请参阅 关于 Amazon AppConfig 扩展

最后,在功能标志属性部分,当您输入新功能标志的属性详细信息时,可以指定约束条件。约束可确保不会将任何意外的属性值部署到您的应用程序中。 Amazon AppConfig 支持以下类型的标志属性及其相应的约束。

类型 约束 描述
String 正则表达式

字符串的正则表达式模式

枚举

字符串的可接受值列表

数字 最低

属性的最小数值

最高

属性的最大数值

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

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

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

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

  2. 在导航窗格中,选择应用程序,然后选择您在中创建的应用程序在 Amazon AppConfig中为应用程序创建命名空间

  3. 选择配置文件和功能标志选项卡,然后选择创建配置

  4. 在 “配置选项” 部分中,选择功能标志

  5. 向下滚动。在配置配置文件部分中,为配置配置文件名称输入一个名称。

  6. (可选)展开描述并输入描述。

  7. (可选)展开其他选项并根据需要完成以下操作。

    1. 加密列表中,从列表中选择一个 Amazon Key Management Service (Amazon KMS) 密钥。

    2. 在 “关联分机” 部分中,从列表中选择一个分机。

    3. 在 “标签” 部分中,选择 “添加新标签”,然后指定键和可选值。

  8. 选择下一步

  9. 在 “功能标志定义” 部分中,为旗帜名称输入一个名称。

  10. 对于 Fla g key,输入一个标志标识符以区分同一配置文件中的标志。同一配置文件中的标志不能具有相同的密钥。创建标志后,可以编辑标志名称,但不能编辑标志键。

  11. (可选)展开描述并输入有关此标志的信息。

  12. 选择 “这是短期标志”,也可以选择应禁用或删除该标志的日期。请注意,这 Amazon AppConfig 不会禁用该标志。

  13. 在 “旗帜属性” 部分中,选择定义属性。属性使您能够在标志中提供其他值。

  14. 对于 Key,指定一个标志键并从 “类型” 列表中选择其类型。您可以选择根据指定的约束来验证属性值。下图显示了一个示例。

    Amazon AppConfig 功能旗帜的旗帜属性示例

    选择 “定义属性” 以添加其他属性。

    注意

    请注意以下信息。

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

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

    • 给定标志的标志属性键必须是唯一的。

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

  15. 在 “功能标志值” 部分中,选择 “启用” 以启用该标志。如果适用,使用同样的开关在标志到达指定的弃用日期时将其禁用。

  16. 选择下一步

  17. 在 “查看并保存” 页面上,验证标志的详细信息,然后单击 “保存” 并继续部署

继续执行在 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 } } }