跳至內容

AppConfig Feature Flags - create a HostedConfiguration using CDK with attributes in my feature flags?

1

I'm running into the "Error invoking extension AppConfig Feature Flags Helper: Invalid 'Content' data" error when deploying a HostedConfiguration using CDK. Here is my CDK setup:

const hostedConfiguration = new HostedConfiguration(this, "ExampleHostedConfiguration", {
      application,
      name: hostedConfigurationName,
      content: ConfigurationContent.fromFile("config/app-config.json"),
      type: ConfigurationType.FEATURE_FLAGS,
      deploymentStrategy: deploymentStrategy
});

and here is my app-config.json file:

{
  "version": "1",
  "flags": {
    "flagOne": {
      "name": "Flag One",
      "attributes": {
        "test": { 
          "description": "This is a test attribute"
        }
      }
    },
    "flagTwo": {
      "name": "Flag Two"
    }
  },
  "values": {
    "flagOne": {
      "enabled": true,
      "test": "10"
    },
    "flagTwo": {
      "enabled": true
    }
  }
}

This JSON matches the schema provided in the AWS documentation: https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-type-reference-feature-flags.html

However when I use CDK deploy it fails with a "Error invoking extension AppConfig Feature Flags Helper: Invalid 'Content' data" exception message.

I believe it's related to attributes specifically because if I use json without the attributes then it successfully deploys. For example

{
  "version": "1",
  "flags": {
    "flagOne": {
      "name": "Flag One"
    },
    "flagTwo": {
      "name": "Flag Two"
    }
  },
  "values": {
    "flagOne": {
      "enabled": true
    },
    "flagTwo": {
      "enabled": true
    }
  }
}

However I would like attributes in my feature flags and the documentation indicates they are included. thank you.

已提問 1 年前檢視次數 1416 次
2 個答案
1
已接受的答案

The AI suggestion above did not work (It also generated a json which didn't pass the schema validation). However it got me to try to deploy with an attribute constraint included. And it worked! So for posterity this is the proper JSON format:

{
  "version": "1",
  "flags": {
    "flagOne": {
      "name": "Flag One",
      "attributes": {
        "test": { 
          "description": "This is a test attribute",
          "constraints": {
            "type": "string"
          }
        }
      }
    },
    "flagTwo": {
      "name": "Flag Two"
    }
  },
  "values": {
    "flagOne": {
      "enabled": true,
      "test": "10"
    },
    "flagTwo": {
      "enabled": true
    }
  }
}

A constraint is REQUIRED in the attribute field for the CDK to deploy however a description is not required. The JSON schema here: https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-type-reference-feature-flags.html is therefore slightly wrong and should be updated by AWS engineers.

已回答 1 年前
專家
已審閱 1 年前
1

The issue you're encountering with the "Invalid 'Content' data" error when deploying a HostedConfiguration using CDK is likely related to how you've structured the attributes in your feature flag configuration.

In AWS AppConfig, feature flag attributes are properties associated with flags to express related information. However, the way you've defined the attributes in your JSON configuration doesn't match the expected format.

To correctly include attributes in your feature flags, you should structure them as key-value pairs directly under each flag, rather than nested under an "attributes" object. Also, the attribute values should be of the supported types (string, number, boolean, string array, or number array), not objects.

Here's how you could modify your JSON configuration to include attributes correctly:

{
  "version": "1",
  "flags": {
    "flagOne": {
      "name": "Flag One",
      "test": {
        "description": "This is a test attribute",
        "constraints": {
          "type": "STRING"
        }
      }
    },
    "flagTwo": {
      "name": "Flag Two"
    }
  },
  "values": {
    "flagOne": {
      "enabled": true,
      "test": "10"
    },
    "flagTwo": {
      "enabled": true
    }
  }
}

In this corrected version, the "test" attribute is directly under "flagOne", and includes a "constraints" field to specify its type. The "values" section remains the same, where you set the actual value for the "test" attribute.

Remember that attribute names must be unique for a given flag, and the word "enabled" is reserved and cannot be used as an attribute name.

By structuring your feature flag configuration in this way, you should be able to successfully deploy your HostedConfiguration using CDK with attributes in your feature flags.
Sources
Creating a feature flag configuration profile in AWS AppConfig - AWS AppConfig
Creating feature flags and free form configuration data in AWS AppConfig - AWS AppConfig

已回答 1 年前
專家
已審閱 1 年前
  • Your suggestion did not work as written, however it got me to try also including a constraint, which I'll explain in a post.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。