- Newest
- Most votes
- Most comments
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:
- 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' });
- 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
Relevant content
- asked 3 years ago
- asked 5 days ago
- AWS OFFICIALUpdated 2 years ago
