Skip to content

Commit ccaf04c

Browse files
committed
docs(feature_flags): fix SAM infra, convert CDK to Python
1 parent 0264294 commit ccaf04c

File tree

1 file changed

+45
-56
lines changed

1 file changed

+45
-56
lines changed

docs/utilities/feature_flags.md

+45-56
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ The following sample infrastructure will be used throughout this documentation:
5252
FeatureStoreApp:
5353
Type: AWS::AppConfig::Application
5454
Properties:
55-
Description: "AppConfig Appliction for feature toggles"
56-
Name: my-app
55+
Description: "AppConfig Application for feature toggles"
56+
Name: product-catalogue
5757

5858
FeatureStoreDevEnv:
5959
Type: AWS::AppConfig::Environment
6060
Properties:
6161
ApplicationId: !Ref FeatureStoreApp
6262
Description: "Development Environment for the App Config Store"
63-
Name: "development"
63+
Name: dev
6464

6565
FeatureStoreConfigProfile:
6666
Type: AWS::AppConfig::ConfigurationProfile
6767
Properties:
6868
ApplicationId: !Ref FeatureStoreApp
69-
Name: "MyTestProfile"
69+
Name: features
7070
LocationUri: "hosted"
7171

7272
HostedConfigVersion:
@@ -110,69 +110,58 @@ The following sample infrastructure will be used throughout this documentation:
110110

111111
=== "CDK"
112112

113-
```typescript hl_lines="2-7 13-32 34-35 40 47 54"
114-
import * as cdk from '@aws-cdk/core';
115-
import {
116-
CfnApplication,
117-
CfnConfigurationProfile, CfnDeployment,
118-
CfnEnvironment,
119-
CfnHostedConfigurationVersion
120-
} from "@aws-cdk/aws-appconfig";
113+
```python hl_lines="13-29 31 33 37 41 47"
114+
import json
121115

122-
export class CdkStack extends cdk.Stack {
123-
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
124-
super(scope, id, props);
116+
import aws_cdk.aws_appconfig as appconfig
117+
from aws_cdk import core
125118

126-
const featureConfig = {
119+
120+
class SampleFeatureFlagStore(core.Construct):
121+
122+
def __init__(self, scope: core.Construct, id_: str) -> None:
123+
super().__init__(scope, id_)
124+
125+
features_config = {
127126
"premium_features": {
128-
"default": false,
127+
"default": False,
129128
"rules": {
130129
"customer tier equals premium": {
131-
"when_match": true,
132-
"conditions": [
133-
{
134-
"action": "EQUALS",
135-
"key": "tier",
136-
"value": "premium"
137-
}
138-
]
130+
"when_match": True,
131+
"conditions": [{
132+
"action": "EQUALS",
133+
"key": "tier",
134+
"value": "premium"
135+
}]
139136
}
140137
}
141138
},
142139
"ten_percent_off_campaign": {
143-
"default": true
140+
"default": True
144141
}
145142
}
146-
147-
const app = new CfnApplication(this, "app", {name: "productapp"});
148-
const env = new CfnEnvironment(this, "env", {
149-
applicationId: app.ref,
150-
name: "dev-env"
151-
});
152-
153-
const configProfile = new CfnConfigurationProfile(this, "profile", {
154-
applicationId: app.ref,
155-
locationUri: "hosted",
156-
name: "configProfile"
157-
});
158-
159-
160-
const hostedConfigVersion = new CfnHostedConfigurationVersion(this, "version", {
161-
applicationId: app.ref,
162-
configurationProfileId: configProfile.ref,
163-
content: JSON.stringify(featureConfig),
164-
contentType: "application/json"
165-
});
166-
167-
new CfnDeployment(this, "deploy", {
168-
applicationId: app.ref,
169-
configurationProfileId: configProfile.ref,
170-
configurationVersion: hostedConfigVersion.ref,
171-
deploymentStrategyId: "AppConfig.AllAtOnce",
172-
environmentId: env.ref
173-
});
174-
}
175-
}
143+
144+
self.config_app = appconfig.CfnApplication(self, id='app', name="product-catalogue")
145+
146+
self.config_env = appconfig.CfnEnvironment(self, id='env',
147+
application_id=self.config_app.ref,
148+
name="dev-env")
149+
150+
self.config_profile = appconfig.CfnConfigurationProfile(self, id='profile',
151+
application_id=self.config_app.ref,
152+
location_uri='hosted', name="features")
153+
154+
self.hosted_cfg_version = appconfig.CfnHostedConfigurationVersion(self, 'version',
155+
application_id=self.config_app.ref,
156+
configuration_profile_id=self.config_profile.ref,
157+
content=json_dumps(features_config),
158+
content_type='application/json')
159+
160+
self.app_config_deployment = appconfig.CfnDeployment(self, id='deploy', application_id=self.config_app.ref,
161+
configuration_profile_id=self.config_profile.ref,
162+
configuration_version=self.hosted_cfg_version.ref,
163+
deployment_strategy_id="AppConfig.AllAtOnce",
164+
environment_id=self.config_env.ref)
176165
```
177166

178167
### Evaluating a single feature flag

0 commit comments

Comments
 (0)