Skip to content

Commit

Permalink
feat(appconfig): inline YAML support for hosted configuration (#27696)
Browse files Browse the repository at this point in the history
Adding an additional helper for using inline content for a YAML config

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
chenjane-dev authored Nov 7, 2023
1 parent 48e5e33 commit de0a9e2
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 14 deletions.
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
});
```

You can define hosted configuration content using any of the following ConfigurationContent methods:

* `fromFile` - Defines the hosted configuration content from a file.
* `fromInlineText` - Defines the hosted configuration from inline text.
* `fromInlineJson` - Defines the hosted configuration from inline JSON.
* `fromInlineYaml` - Defines the hosted configuration from inline YAML.
* `fromInline` - Defines the hosted configuration from user-specified content types.

AWS AppConfig supports the following types of configuration profiles.

* **Feature flag**: Use a feature flag configuration to turn on new features that require a timely deployment, such as a product launch or announcement.
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,18 @@ export abstract class ConfigurationContent {
};
}

/**
* Defines the hosted configuration content as YAML from inline code.
*
* @param content The inline code that defines the configuration content
*/
public static fromInlineYaml(content: string): ConfigurationContent {
return {
content,
contentType: 'application/x-yaml',
};
}

/**
* The configuration content.
*/
Expand Down
33 changes: 33 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/test/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,39 @@ describe('configuration', () => {
});
});

test('default configuration from inline yaml', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig');
new HostedConfiguration(stack, 'MyConfiguration', {
deploymentStrategy: new DeploymentStrategy(stack, 'MyDeploymentStrategy', {
rolloutStrategy: RolloutStrategy.linear({
growthFactor: 15,
deploymentDuration: cdk.Duration.minutes(30),
}),
}),
application: app,
content: ConfigurationContent.fromInlineYaml('This should be of content type application/x-yaml'),
});

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
Name: 'MyConfiguration',
ApplicationId: {
Ref: 'MyAppConfigB4B63E75',
},
LocationUri: 'hosted',
});
Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::HostedConfigurationVersion', {
ApplicationId: {
Ref: 'MyAppConfigB4B63E75',
},
ConfigurationProfileId: {
Ref: 'MyConfigurationConfigurationProfileEE0ECA85',
},
Content: 'This should be of content type application/x-yaml',
ContentType: 'application/x-yaml',
});
});

test('configuration profile with name', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
"Name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromJson-140D2DDD"
}
},
"MyAppConfigHostedEnvFromYaml82D3D1B2": {
"Type": "AWS::AppConfig::Environment",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"Name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromYaml-BB2C802A"
}
},
"MyAppConfigParameterEnvD769FB19": {
"Type": "AWS::AppConfig::Environment",
"Properties": {
Expand Down Expand Up @@ -175,6 +184,51 @@
}
}
},
"MyHostedConfigFromYamlConfigurationProfile7C77A435": {
"Type": "AWS::AppConfig::ConfigurationProfile",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"LocationUri": "hosted",
"Name": "awsappconfigconfiguration-MyHostedConfigFromYaml-87E9786A"
}
},
"MyHostedConfigFromYaml13C5BE35": {
"Type": "AWS::AppConfig::HostedConfigurationVersion",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"ConfigurationProfileId": {
"Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435"
},
"Content": "This is the configuration content",
"ContentType": "application/x-yaml"
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigFromYamlDeploymentFE9624CBE5FC6": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"ConfigurationProfileId": {
"Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435"
},
"ConfigurationVersion": {
"Ref": "MyHostedConfigFromYaml13C5BE35"
},
"DeploymentStrategyId": {
"Ref": "MyDeployStrategy062CAEA2"
},
"EnvironmentId": {
"Ref": "MyAppConfigHostedEnvFromYaml82D3D1B2"
}
}
},
"MyValidatorFunctionServiceRole5CD02390": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit de0a9e2

Please sign in to comment.