Skip to content

Unable to deploy multiple versions of FreeForm configuration in single appConfig

0

I am trying to add multiple versions of a free form configuration to a single hosted configuration using aws cdk. I am unable to figure out a way to that. Is there a way I can do that. Basically I am using appConfig to fetch a variable at runtime using lambda. I want different versions in hostedConfiguration to host different values for the variable.

        this.hostedConfiguration = new HostedConfiguration(this, 'HostedConfiguration', {
            application: this.application,
            content: ConfigurationContent.fromFile(APP_CONFIG_FILE_PATH),
            deployTo: [this.configEnvironment],
            type: props.configType
        });
1 Answer
0

To deploy multiple versions of a freeform configuration in AWS AppConfig using CDK, you need to understand that the HostedConfiguration construct creates a single configuration version. To create multiple versions, you'll need to use the CfnHostedConfigurationVersion construct directly.

Here's how you can approach this:

  1. First, create your application and configuration profile:
const app = new appconfig.Application(this, 'MyApp');
const env = new appconfig.Environment(this, 'MyEnv', {
application: app,
});

// Create a configuration profile
const configProfile = new appconfig.CfnConfigurationProfile(this, 'ConfigProfile', {
applicationId: app.applicationId,
name: 'MyConfigProfile',
locationUri: 'hosted',
type: 'AWS.Freeform'
});
  1. Then create multiple versions of the configuration:
// First version
const version1 = new appconfig.CfnHostedConfigurationVersion(this, 'Version1', {
applicationId: app.applicationId,
configurationProfileId: configProfile.ref,
content: 'my first config value',
contentType: 'text/plain'
});

// Second version with latestVersionNumber to prevent race conditions
const version2 = new appconfig.CfnHostedConfigurationVersion(this, 'Version2', {
applicationId: app.applicationId,
configurationProfileId: configProfile.ref,
content: 'my second config value',
contentType: 'text/plain',
latestVersionNumber: 1 // Reference to the first version
});

The latestVersionNumber property is important when creating multiple versions in succession as it acts as a locking token to prevent race conditions from overwriting configuration updates.

When deploying configurations to an environment, note that AWS AppConfig only allows one configuration deployment at a time to a specific environment. The deployments will occur sequentially in the order they are declared.

For your Lambda to fetch different versions at runtime, you'll need to specify which version you want to retrieve when calling the AWS AppConfig API from your Lambda function.
Sources
aws-cdk-lib.aws_appconfig module · AWS CDK
class CfnHostedConfigurationVersion (construct) · AWS CDK
interface CfnHostedConfigurationVersionProps · AWS CDK
interface CfnConfigurationProfileProps · AWS CDK

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.