本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Amazon AppConfig 代理本地开发模式的功能标志示例
本节包含可在本地开发模式下与 Amazon AppConfig Agent 一起使用的功能标志示例。本地开发模式期望功能标志数据采用数据检索时格式。检索时间格式是从 GetLatestConfigurationAPI 检索标志时返回的格式,它仅包含标志的值。检索时间格式不包括标志的完整定义(传递给 API)。CreateHostedConfigurationVersion标志的完整定义还包含诸如属性名称和值、约束条件以及标志的启用状态等信息。
基本功能标志示例
在本地开发模式下,在 Amazon AppConfig Agent 中使用以下基本功能标志示例。
注意
如果您希望代理将本地要素标志数据的内容类型报告为application/json(就像在非本地开发模式的环境 Amazon AppConfig 中检索标志数据时一样),则您的本地功能标志文件必须使用.json 扩展名。例如 Local:MyFeatureFlags:SampleB1.json。
示例 1:表示 UI 刷新的单个标志。
{ "ui_refresh": { "enabled": true, "new_styleguide_colors": true } }
示例 2:表示操作功能标志的多个标志。
{ "background_worker": { "enabled": true, "num_threads": 4, "queue_name": "MyWorkQueue" }, "emergency_shutoff_switch": { "enabled": false }, "logger_settings": { "enabled": true, "level": "INFO" } }
多变量功能标志示例
包含至少一个多变量功能标志的功能标志配置的检索时格式表示为 Amazon Ion
为使代理能正确解析这些文件,您的本地功能标志文件必须使用以下扩展名:.application%ion%type=AWS.AppConfig.FeatureFlags。例如 Local:MyFeatureFlags:SampleMV1.application%ion%type=AWS.AppConfig.FeatureFlags。
示例 1:表示新功能分级发布的多变量标志。
'tiered_release'::[ [ (or (and (eq $group "Tier1") (split by::$userId pct::1 seed::"2025.01.01")) (and (eq $group "Tier2") (split by::$userId pct::7 seed::"2025.01.01"))), '''{"_variant": "ShowFeature", "enabled": true}''' ], '''{"_variant": "HideFeature", "enabled": false}''' ]
示例 2:基于用户 ID 显示不同 UX 界面的多个标志。前两个标志为多变量标志,最后一个标志为基本标志。
'colorway'::[ [ (contains $userId "beta"), '''{"_variant": "BetaTesters", "enabled": true, "background": "blue", "foreground": "red"}''', ], [ (split by::$userId pct::10), '''{"_variant": "SplitRollOutRedAndBlue", "enabled": true, "background": "blue", "foreground": "red"}''', ], '''{"_variant": "default", "enabled": true, "background": "green", "foreground": "green"}''', ] 'simple_feature'::[ [ (contains $userId "beta"), '''{"_variant": "BetaTesters", "enabled": true}''' ], '''{"_variant": "default", "enabled": false}''' ] 'button_color'::'''{"enabled": true, "color": "orange"}'''