如何为AWS AppConfig功能标志添加带数值约束的percentEnabled属性?
为AWS AppConfig功能标志添加数值属性的CloudFormation实现
需求:
- 已通过CloudFormation创建AWS AppConfig的ConfigurationProfile与HostedConfigurationVersion(类型为
AWS.AppConfig.FeatureFlags),现有isFooFlagEnabled功能标志 - 需为该标志添加名为
percentEnabled的属性,要求:- 数值类型
- 取值范围0-100之间
以下是实现该需求的CloudFormation代码:
"AppConfigProfileId": { "Type": "AWS::AppConfig::ConfigurationProfile", "Properties": { "ApplicationId": { "Ref": "AppConfig" }, "Description": "Foo服务所有功能标志的顶级容器", "Name": "FeatureFlags", "LocationUri": "hosted", "Type": "AWS.AppConfig.FeatureFlags" } }, "AppConfigFeatureFlagVersion": { "Type": "AWS::AppConfig::HostedConfigurationVersion", "Properties": { "ApplicationId": { "Ref": "AppConfig" }, "ConfigurationProfileId": { "Ref": "AppConfigProfileId" }, "Content": { "Fn::Join": [ "\n", [ "{", " \"flags\": {", " \"isFooFlagEnabled\": {", " \"name\": \"isFooFlagEnabled\",", " \"schema\": {", " \"type\": \"object\",", " \"properties\": {", " \"percentEnabled\": {", " \"type\": \"number\",", " \"minimum\": 0,", " \"maximum\": 100", " } },", " \"required\": [\"percentEnabled\"]", " } " },", " },", " \"values\": {", " \"isFooFlagEnabled\": {", " \"enabled\": false,", " \"percentEnabled\": 0", " } " },", " \"version\": \"1\"", "}" ] ] }, "ContentType": "application/json", "Description": "Foo标志的托管配置版本" } }
实现说明:
- 在
flags下的isFooFlagEnabled节点中添加schema定义,明确percentEnabled为数值类型,同时通过minimum和maximum约束取值范围在0到100之间 - 在
values节点中为isFooFlagEnabled设置percentEnabled的初始值,这里设为0
内容的提问来源于stack exchange,提问作者user2185573
相关产品推荐
相关产品推荐

