|
| 1 | +import json |
| 2 | + |
| 3 | +import aws_cdk.aws_appconfig as appconfig |
| 4 | +from aws_cdk import core |
| 5 | + |
| 6 | + |
| 7 | +class SampleFeatureFlagStore(core.Construct): |
| 8 | + def __init__(self, scope: core.Construct, id_: str) -> None: |
| 9 | + super().__init__(scope, id_) |
| 10 | + |
| 11 | + features_config = { |
| 12 | + "premium_features": { |
| 13 | + "default": False, |
| 14 | + "rules": { |
| 15 | + "customer tier equals premium": { |
| 16 | + "when_match": True, |
| 17 | + "conditions": [{"action": "EQUALS", "key": "tier", "value": "premium"}], |
| 18 | + } |
| 19 | + }, |
| 20 | + }, |
| 21 | + "ten_percent_off_campaign": {"default": True}, |
| 22 | + } |
| 23 | + |
| 24 | + self.config_app = appconfig.CfnApplication( |
| 25 | + self, |
| 26 | + id="app", |
| 27 | + name="product-catalogue", |
| 28 | + ) |
| 29 | + self.config_env = appconfig.CfnEnvironment( |
| 30 | + self, |
| 31 | + id="env", |
| 32 | + application_id=self.config_app.ref, |
| 33 | + name="dev-env", |
| 34 | + ) |
| 35 | + self.config_profile = appconfig.CfnConfigurationProfile( |
| 36 | + self, |
| 37 | + id="profile", |
| 38 | + application_id=self.config_app.ref, |
| 39 | + location_uri="hosted", |
| 40 | + name="features", |
| 41 | + ) |
| 42 | + self.hosted_cfg_version = appconfig.CfnHostedConfigurationVersion( |
| 43 | + self, |
| 44 | + "version", |
| 45 | + application_id=self.config_app.ref, |
| 46 | + configuration_profile_id=self.config_profile.ref, |
| 47 | + content=json.dumps(features_config), |
| 48 | + content_type="application/json", |
| 49 | + ) |
| 50 | + self.app_config_deployment = appconfig.CfnDeployment( |
| 51 | + self, |
| 52 | + id="deploy", |
| 53 | + application_id=self.config_app.ref, |
| 54 | + configuration_profile_id=self.config_profile.ref, |
| 55 | + configuration_version=self.hosted_cfg_version.ref, |
| 56 | + deployment_strategy_id="AppConfig.AllAtOnce", |
| 57 | + environment_id=self.config_env.ref, |
| 58 | + ) |
0 commit comments