Search code examples
amazon-web-servicesaws-cloudformationaws-app-config

How to setup AWS AppConfig feature flag hosted configuration version with properties


I am trying to setup a hosted configuration version in app config for a feature flag with some attributes (https://aws.amazon.com/blogs/mt/using-aws-appconfig-feature-flags/)

"AppConfigProfileId": {
      "Type": "AWS::AppConfig::ConfigurationProfile",
      "Properties": {
        "ApplicationId": {
          "Ref": "AppConfig"
        },
        "Description": "Top level container for all the feature flags in Foo Service",
        "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\"",
                "       }",
                "    },",
                "    \"values\": {",
                "        \"isFooFlagEnabled\": {",
                "            \"enabled\": false",
                "        }",
                "    },",
                "    \"version\": \"1\"",
                "}"
            ]
          ]
        },
        "ContentType": "application/json",
        "Description": "Hosted configuration version for foo flag"
      }
    }

I am trying to add an extra attribute attached to isFooFlagEnabled called percentEnabled

I would like that flag to

  1. Be a number
  2. Be constrained to be in between 0 and 100.

What is the syntax/CFN code to accomplish this. I have been looking around cloudformation and app config documentation and so far have not found a solution.


Solution

  • I managed to solve this problem by

    "AppConfigFeatureFlagVersion": {
          "Type": "AWS::AppConfig::HostedConfigurationVersion",
          "Properties": {
            "ApplicationId": {
              "Ref": "AppConfig"
            },
            "ConfigurationProfileId": {
              "Ref": "AppConfigProfileId"
            },
            "Content": {
              "Fn::ToJsonString": {
                "flags": {
                  "isFooFlagEnabled": {
                    "attributes": {
                      "percentEnabled": {
                        "constraints": {
                          "maximum": 100,
                          "minimum": 0,
                          "type": "number"
                        }
                      }
                    },
                    "name": "isFooFlagEnabled"
                  }
                },
                "values": {
                  "isFooFlagEnabled": {
                    "percentEnabled": 0,
                    "enabled": false
                  }
                },
                "version": "1"
              }
            },
    

    By following the example from https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appconfig-configurationprofile.html#cfn-appconfig-configurationprofile-type

    I also used the language extensions in https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-languageextension-transform.html to get Fn::ToJsonString to remove the nested json as well.