Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(feature-toggles): correct cdk example #601

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 59 additions & 51 deletions docs/utilities/feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,59 +110,67 @@ The following sample infrastructure will be used throughout this documentation:

=== "CDK"

```python hl_lines="13-29 31 33 37 41 47"
import json

import aws_cdk.aws_appconfig as appconfig
from aws_cdk import core
```python hl_lines="11-22 24 29 35 42 50"
import json

import aws_cdk.aws_appconfig as appconfig
from aws_cdk import core


class SampleFeatureFlagStore(core.Construct):
def __init__(self, scope: core.Construct, id_: str) -> None:
super().__init__(scope, id_)

features_config = {
"premium_features": {
"default": False,
"rules": {
"customer tier equals premium": {
"when_match": True,
"conditions": [{"action": "EQUALS", "key": "tier", "value": "premium"}],
}
},
},
"ten_percent_off_campaign": {"default": True},
}

self.config_app = appconfig.CfnApplication(
self,
id="app",
name="product-catalogue",
)
self.config_env = appconfig.CfnEnvironment(
self,
id="env",
application_id=self.config_app.ref,
name="dev-env",
)
self.config_profile = appconfig.CfnConfigurationProfile(
self,
id="profile",
application_id=self.config_app.ref,
location_uri="hosted",
name="features",
)
self.hosted_cfg_version = appconfig.CfnHostedConfigurationVersion(
self,
"version",
application_id=self.config_app.ref,
configuration_profile_id=self.config_profile.ref,
content=json.dumps(features_config),
content_type="application/json",
)
self.app_config_deployment = appconfig.CfnDeployment(
self,
id="deploy",
application_id=self.config_app.ref,
configuration_profile_id=self.config_profile.ref,
configuration_version=self.hosted_cfg_version.ref,
deployment_strategy_id="AppConfig.AllAtOnce",
environment_id=self.config_env.ref,
)

class SampleFeatureFlagStore(core.Construct):
def __init__(self, scope: core.Construct, id_: str) -> None:
super().__init__(scope, id_)
features_config = {
"premium_features": {
"default": False,
"rules": {
"customer tier equals premium": {
"when_match": True,
"conditions": [{
"action": "EQUALS",
"key": "tier",
"value": "premium"
}]
}
}
},
"ten_percent_off_campaign": {
"default": True
}
}
self.config_app = appconfig.CfnApplication(self, id='app', name="product-catalogue")

self.config_env = appconfig.CfnEnvironment(self, id='env',
application_id=self.config_app.ref,
name="dev-env")

self.config_profile = appconfig.CfnConfigurationProfile(self, id='profile',
application_id=self.config_app.ref,
location_uri='hosted', name="features")
self.hosted_cfg_version = appconfig.CfnHostedConfigurationVersion(self, 'version',
application_id=self.config_app.ref,
configuration_profile_id=self.config_profile.ref,
content=json_dumps(features_config),
content_type='application/json')
self.app_config_deployment = appconfig.CfnDeployment(self, id='deploy', application_id=self.config_app.ref,
configuration_profile_id=self.config_profile.ref,
configuration_version=self.hosted_cfg_version.ref,
deployment_strategy_id="AppConfig.AllAtOnce",
environment_id=self.config_env.ref)
```
```

### Evaluating a single feature flag

Expand Down