Skip to content

Commit de0a9e2

Browse files
authored
feat(appconfig): inline YAML support for hosted configuration (#27696)
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*
1 parent 48e5e33 commit de0a9e2

11 files changed

+259
-14
lines changed

packages/@aws-cdk/aws-appconfig-alpha/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
8383
});
8484
```
8585

86+
You can define hosted configuration content using any of the following ConfigurationContent methods:
87+
88+
* `fromFile` - Defines the hosted configuration content from a file.
89+
* `fromInlineText` - Defines the hosted configuration from inline text.
90+
* `fromInlineJson` - Defines the hosted configuration from inline JSON.
91+
* `fromInlineYaml` - Defines the hosted configuration from inline YAML.
92+
* `fromInline` - Defines the hosted configuration from user-specified content types.
93+
8694
AWS AppConfig supports the following types of configuration profiles.
8795

8896
* **Feature flag**: Use a feature flag configuration to turn on new features that require a timely deployment, such as a product launch or announcement.

packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts

+12
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,18 @@ export abstract class ConfigurationContent {
828828
};
829829
}
830830

831+
/**
832+
* Defines the hosted configuration content as YAML from inline code.
833+
*
834+
* @param content The inline code that defines the configuration content
835+
*/
836+
public static fromInlineYaml(content: string): ConfigurationContent {
837+
return {
838+
content,
839+
contentType: 'application/x-yaml',
840+
};
841+
}
842+
831843
/**
832844
* The configuration content.
833845
*/

packages/@aws-cdk/aws-appconfig-alpha/test/configuration.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,39 @@ describe('configuration', () => {
434434
});
435435
});
436436

437+
test('default configuration from inline yaml', () => {
438+
const stack = new cdk.Stack();
439+
const app = new Application(stack, 'MyAppConfig');
440+
new HostedConfiguration(stack, 'MyConfiguration', {
441+
deploymentStrategy: new DeploymentStrategy(stack, 'MyDeploymentStrategy', {
442+
rolloutStrategy: RolloutStrategy.linear({
443+
growthFactor: 15,
444+
deploymentDuration: cdk.Duration.minutes(30),
445+
}),
446+
}),
447+
application: app,
448+
content: ConfigurationContent.fromInlineYaml('This should be of content type application/x-yaml'),
449+
});
450+
451+
Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
452+
Name: 'MyConfiguration',
453+
ApplicationId: {
454+
Ref: 'MyAppConfigB4B63E75',
455+
},
456+
LocationUri: 'hosted',
457+
});
458+
Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::HostedConfigurationVersion', {
459+
ApplicationId: {
460+
Ref: 'MyAppConfigB4B63E75',
461+
},
462+
ConfigurationProfileId: {
463+
Ref: 'MyConfigurationConfigurationProfileEE0ECA85',
464+
},
465+
Content: 'This should be of content type application/x-yaml',
466+
ContentType: 'application/x-yaml',
467+
});
468+
});
469+
437470
test('configuration profile with name', () => {
438471
const stack = new cdk.Stack();
439472
const app = new Application(stack, 'MyAppConfig');

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/appconfigconfigurationDefaultTestDeployAssert6752CD38.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.template.json

+54
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
"Name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromJson-140D2DDD"
2525
}
2626
},
27+
"MyAppConfigHostedEnvFromYaml82D3D1B2": {
28+
"Type": "AWS::AppConfig::Environment",
29+
"Properties": {
30+
"ApplicationId": {
31+
"Ref": "MyAppConfigB4B63E75"
32+
},
33+
"Name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromYaml-BB2C802A"
34+
}
35+
},
2736
"MyAppConfigParameterEnvD769FB19": {
2837
"Type": "AWS::AppConfig::Environment",
2938
"Properties": {
@@ -175,6 +184,51 @@
175184
}
176185
}
177186
},
187+
"MyHostedConfigFromYamlConfigurationProfile7C77A435": {
188+
"Type": "AWS::AppConfig::ConfigurationProfile",
189+
"Properties": {
190+
"ApplicationId": {
191+
"Ref": "MyAppConfigB4B63E75"
192+
},
193+
"LocationUri": "hosted",
194+
"Name": "awsappconfigconfiguration-MyHostedConfigFromYaml-87E9786A"
195+
}
196+
},
197+
"MyHostedConfigFromYaml13C5BE35": {
198+
"Type": "AWS::AppConfig::HostedConfigurationVersion",
199+
"Properties": {
200+
"ApplicationId": {
201+
"Ref": "MyAppConfigB4B63E75"
202+
},
203+
"ConfigurationProfileId": {
204+
"Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435"
205+
},
206+
"Content": "This is the configuration content",
207+
"ContentType": "application/x-yaml"
208+
},
209+
"UpdateReplacePolicy": "Retain",
210+
"DeletionPolicy": "Retain"
211+
},
212+
"MyHostedConfigFromYamlDeploymentFE9624CBE5FC6": {
213+
"Type": "AWS::AppConfig::Deployment",
214+
"Properties": {
215+
"ApplicationId": {
216+
"Ref": "MyAppConfigB4B63E75"
217+
},
218+
"ConfigurationProfileId": {
219+
"Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435"
220+
},
221+
"ConfigurationVersion": {
222+
"Ref": "MyHostedConfigFromYaml13C5BE35"
223+
},
224+
"DeploymentStrategyId": {
225+
"Ref": "MyDeployStrategy062CAEA2"
226+
},
227+
"EnvironmentId": {
228+
"Ref": "MyAppConfigHostedEnvFromYaml82D3D1B2"
229+
}
230+
}
231+
},
178232
"MyValidatorFunctionServiceRole5CD02390": {
179233
"Type": "AWS::IAM::Role",
180234
"Properties": {

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/manifest.json

+28-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)