Skip to content

Commit 6333eb4

Browse files
authored
chore(appconfig): refactor README and integ tests (#29017)
### Reason for this change Making changes after API review. ### Description of changes Refactor README and integ tests. ### Description of how you validated changes ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2e4067b commit 6333eb4

14 files changed

+163
-96
lines changed

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

+123-82
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,87 @@
1818

1919
This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project.
2020

21-
Use AWS AppConfig, a capability of AWS Systems Manager, to create, manage, and quickly deploy application configurations. A configuration is a collection of settings that influence the behavior of your application. You can use AWS AppConfig with applications hosted on Amazon Elastic Compute Cloud (Amazon EC2) instances, AWS Lambda, containers, mobile applications, or IoT devices. To view examples of the types of configurations you can manage by using AWS AppConfig, see [Example configurations](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-configuration-and-profile.html#appconfig-creating-configuration-and-profile-examples).
21+
For a high level overview of what AWS AppConfig is and how it works, please take a look here:
22+
[What is AWS AppConfig?](https://docs.aws.amazon.com/appconfig/latest/userguide/what-is-appconfig.html)
23+
24+
25+
## Basic Hosted Configuration Use Case
26+
27+
> The main way most AWS AppConfig users utilize the service is through hosted configuration, which involves storing
28+
> configuration data directly within AWS AppConfig.
29+
30+
An example use case:
31+
32+
```ts
33+
const app = new appconfig.Application(this, 'MyApp');
34+
const env = new appconfig.Environment(this, 'MyEnv', {
35+
application: app,
36+
});
37+
38+
new appconfig.HostedConfiguration(this, 'MyHostedConfig', {
39+
application: app,
40+
deployTo: [env],
41+
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
42+
});
43+
```
44+
45+
This will create the application and environment for your configuration and then deploy your configuration to the
46+
specified environment.
47+
48+
For more information about what these resources are: [Creating feature flags and free form configuration data in AWS AppConfig](https://docs.aws.amazon.com/appconfig/latest/userguide/creating-feature-flags-and-configuration-data.html).
49+
50+
For more information about deploying configuration: [Deploying feature flags and configuration data in AWS AppConfig](https://docs.aws.amazon.com/appconfig/latest/userguide/deploying-feature-flags.html)
51+
52+
____
53+
54+
For an in-depth walkthrough of specific resources and how to use them, please take a look at the following sections.
2255

2356
## Application
2457

25-
In AWS AppConfig, an application is simply an organizational construct like a folder. This organizational construct has a
26-
relationship with some unit of executable code. For example, you could create an application called MyMobileApp to organize and
27-
manage configuration data for a mobile application installed by your users. Configurations and environments are associated with
28-
the application.
58+
[AWS AppConfig Application Documentation](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-namespace.html)
2959

30-
The name and description of an application are optional.
60+
In AWS AppConfig, an application is simply an organizational
61+
construct like a folder. Configurations and environments are
62+
associated with the application.
63+
64+
When creating an application through CDK, the name and
65+
description of an application are optional.
3166

3267
Create a simple application:
3368

3469
```ts
3570
new appconfig.Application(this, 'MyApplication');
3671
```
3772

38-
Create an application with a name and description:
73+
## Environment
74+
75+
[AWS AppConfig Environment Documentation](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-environment.html)
76+
77+
Basic environment with monitors:
3978

4079
```ts
41-
new appconfig.Application(this, 'MyApplication', {
42-
applicationName: 'App1',
43-
description: 'This is my application created through CDK.',
80+
declare const application: appconfig.Application;
81+
declare const alarm: cloudwatch.Alarm;
82+
declare const compositeAlarm: cloudwatch.CompositeAlarm;
83+
84+
new appconfig.Environment(this, 'MyEnvironment', {
85+
application,
86+
monitors: [
87+
appconfig.Monitor.fromCloudWatchAlarm(alarm),
88+
appconfig.Monitor.fromCloudWatchAlarm(compositeAlarm),
89+
],
4490
});
4591
```
4692

93+
Environment monitors also support L1 `CfnEnvironment.MonitorsProperty` constructs through the `fromCfnMonitorsProperty` method.
94+
However, this is not the recommended approach for CloudWatch alarms because a role will not be auto-generated if not provided.
95+
4796
## Deployment Strategy
4897

49-
A deployment strategy defines how a configuration will roll out. The roll out is defined by four parameters: deployment type,
50-
step percentage, deployment time, and bake time.
51-
See: https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-deployment-strategy.html
98+
[AWS AppConfig Deployment Strategy Documentation](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-deployment-strategy.html)
99+
100+
A deployment strategy defines how a configuration will roll out. The roll out is defined by four parameters: deployment type,
101+
growth factor, deployment duration, and final bake time.
52102

53103
Deployment strategy with predefined values:
54104

@@ -70,13 +120,13 @@ new appconfig.DeploymentStrategy(this, 'MyDeploymentStrategy', {
70120
});
71121
```
72122

73-
Importing a deployment strategy by ID:
123+
Referencing a deployment strategy by ID:
74124

75125
```ts
76126
appconfig.DeploymentStrategy.fromDeploymentStrategyId(this, 'MyImportedDeploymentStrategy', appconfig.DeploymentStrategyId.fromString('abc123'));
77127
```
78128

79-
Importing an AWS AppConfig predefined deployment strategy by ID:
129+
Referencing an AWS AppConfig predefined deployment strategy by ID:
80130

81131
```ts
82132
appconfig.DeploymentStrategy.fromDeploymentStrategyId(
@@ -98,6 +148,22 @@ A hosted configuration represents configuration stored in the AWS AppConfig host
98148
takes in the configuration content and associated AWS AppConfig application. On construction of a hosted configuration, the
99149
configuration is deployed.
100150

151+
You can define hosted configuration content using any of the following ConfigurationContent methods:
152+
153+
* `fromFile` - Defines the hosted configuration content from a file (you can specify a relative path). The content type will
154+
be determined by the file extension unless specified.
155+
156+
```ts
157+
declare const application: appconfig.Application;
158+
159+
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
160+
application,
161+
content: appconfig.ConfigurationContent.fromFile('config.json'),
162+
});
163+
```
164+
165+
* `fromInlineText` - Defines the hosted configuration from inline text. The content type will be set as `text/plain`.
166+
101167
```ts
102168
declare const application: appconfig.Application;
103169

@@ -107,18 +173,43 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
107173
});
108174
```
109175

110-
You can define hosted configuration content using any of the following ConfigurationContent methods:
176+
* `fromInlineJson` - Defines the hosted configuration from inline JSON. The content type will be set as `application/json` unless specified.
111177

112-
* `fromFile` - Defines the hosted configuration content from a file (you can specify a relative path).
113-
* `fromInlineText` - Defines the hosted configuration from inline text.
114-
* `fromInlineJson` - Defines the hosted configuration from inline JSON.
115-
* `fromInlineYaml` - Defines the hosted configuration from inline YAML.
116-
* `fromInline` - Defines the hosted configuration from user-specified content types.
178+
```ts
179+
declare const application: appconfig.Application;
180+
181+
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
182+
application,
183+
content: appconfig.ConfigurationContent.fromInlineJson('{}'),
184+
});
185+
```
186+
187+
* `fromInlineYaml` - Defines the hosted configuration from inline YAML. The content type will be set as `application/x-yaml`.
188+
189+
```ts
190+
declare const application: appconfig.Application;
191+
192+
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
193+
application,
194+
content: appconfig.ConfigurationContent.fromInlineYaml('MyConfig: This is my content.'),
195+
});
196+
```
197+
198+
* `fromInline` - Defines the hosted configuration from user-specified content types. The content type will be set as `application/octet-stream` unless specified.
199+
200+
```ts
201+
declare const application: appconfig.Application;
202+
203+
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
204+
application,
205+
content: appconfig.ConfigurationContent.fromInline('This is my configuration content.'),
206+
});
207+
```
117208

118209
AWS AppConfig supports the following types of configuration profiles.
119210

120-
* **Feature flag**: Use a feature flag configuration to turn on new features that require a timely deployment, such as a product launch or announcement.
121-
* **Freeform**: Use a freeform configuration to carefully introduce changes to your application.
211+
* **[Feature flag](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-configuration-and-profile-feature-flags.html)**: Use a feature flag configuration to turn on new features that require a timely deployment, such as a product launch or announcement.
212+
* **[Freeform](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-free-form-configurations-creating.html)**: Use a freeform configuration to carefully introduce changes to your application.
122213

123214
A hosted configuration with type:
124215

@@ -192,24 +283,18 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
192283
});
193284
```
194285

195-
To deploy a configuration to an environment after initialization use the `deploy` method:
196-
197-
```ts
198-
declare const application: appconfig.Application;
199-
declare const env: appconfig.Environment;
200-
201-
const config = new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
202-
application,
203-
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
204-
});
286+
### SourcedConfiguration
205287

206-
config.deploy(env);
207-
```
288+
A sourced configuration represents configuration stored in any of the following:
208289

209-
### SourcedConfiguration
290+
* Amazon S3 bucket
291+
* AWS Secrets Manager secret
292+
* Systems Manager
293+
* (SSM) Parameter Store parameter
294+
* SSM document
295+
* AWS CodePipeline.
210296

211-
A sourced configuration represents configuration stored in an Amazon S3 bucket, AWS Secrets Manager secret, Systems Manager
212-
(SSM) Parameter Store parameter, SSM document, or AWS CodePipeline. A sourced configuration takes in the location source
297+
A sourced configuration takes in the location source
213298
construct and optionally a version number to deploy. On construction of a sourced configuration, the configuration is deployed
214299
only if a version number is specified.
215300

@@ -356,50 +441,6 @@ new appconfig.SourcedConfiguration(this, 'MySourcedConfiguration', {
356441
});
357442
```
358443

359-
The `deployTo` parameter is used to specify which environments to deploy the configuration to. If this parameter is not
360-
specified, there will not be a deployment.
361-
362-
A sourced configuration with `deployTo`:
363-
364-
```ts
365-
declare const application: appconfig.Application;
366-
declare const bucket: s3.Bucket;
367-
declare const env: appconfig.Environment;
368-
369-
new appconfig.SourcedConfiguration(this, 'MySourcedConfiguration', {
370-
application,
371-
location: appconfig.ConfigurationSource.fromBucket(bucket, 'path/to/file.json'),
372-
deployTo: [env],
373-
});
374-
```
375-
376-
## Environment
377-
378-
For each AWS AppConfig application, you define one or more environments. An environment is a logical deployment group of AWS
379-
AppConfig targets, such as applications in a Beta or Production environment. You can also define environments for application
380-
subcomponents such as the Web, Mobile, and Back-end components for your application. You can configure Amazon CloudWatch alarms
381-
for each environment. The system monitors alarms during a configuration deployment. If an alarm is triggered, the system rolls
382-
back the configuration.
383-
384-
Basic environment with monitors:
385-
386-
```ts
387-
declare const application: appconfig.Application;
388-
declare const alarm: cloudwatch.Alarm;
389-
declare const compositeAlarm: cloudwatch.CompositeAlarm;
390-
391-
new appconfig.Environment(this, 'MyEnvironment', {
392-
application,
393-
monitors: [
394-
appconfig.Monitor.fromCloudWatchAlarm(alarm),
395-
appconfig.Monitor.fromCloudWatchAlarm(compositeAlarm),
396-
],
397-
});
398-
```
399-
400-
Environment monitors also support L1 CfnEnvironment.MonitorsProperty constructs. However, this is not the recommended approach
401-
for CloudWatch alarms because a role will not be auto-generated if not provided.
402-
403444
## Extension
404445

405446
An extension augments your ability to inject logic or behavior at different points during the AWS AppConfig workflow of

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,11 @@ export abstract class Monitor {
348348
* @param monitorsProperty The monitors property.
349349
*/
350350
public static fromCfnMonitorsProperty(monitorsProperty: CfnEnvironment.MonitorsProperty): Monitor {
351+
if (monitorsProperty.alarmArn === undefined) {
352+
throw new Error('You must specify an alarmArn property to use "fromCfnMonitorsProperty".');
353+
}
351354
return {
352-
alarmArn: monitorsProperty.alarmArn!,
355+
alarmArn: monitorsProperty.alarmArn,
353356
alarmRoleArn: monitorsProperty.alarmRoleArn,
354357
monitorType: MonitorType.CFN_MONITORS_PROPERTY,
355358
};

packages/@aws-cdk/aws-appconfig-alpha/test/integ.application.js.snapshot/appconfigapplicationDefaultTestDeployAssertD6537C40.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.application.js.snapshot/aws-appconfig-application.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.application.js.snapshot/aws-appconfig-application.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Type": "AWS::AppConfig::Application",
55
"Properties": {
66
"Description": "This is my application for testing",
7-
"Name": "awsappconfigapplication-MyAppConfig-5BFACBE9"
7+
"Name": "MySampleApplication"
88
}
99
},
1010
"MyTaskDefTaskRole727F9D3B": {

packages/@aws-cdk/aws-appconfig-alpha/test/integ.application.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.application.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.application.js.snapshot/manifest.json

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

0 commit comments

Comments
 (0)