Skip to content

Commit a3cde4c

Browse files
author
Michael Brewer
committed
Merge branch 'develop' into feat-apigw-prefix
2 parents 2163fc1 + f627b02 commit a3cde4c

File tree

2 files changed

+69
-51
lines changed

2 files changed

+69
-51
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) fo
1414
* **deps:** bump poetry to latest ([#592](https://github.com/awslabs/aws-lambda-powertools-python/issues/592))
1515
* **feature-flags:** bug handling multiple conditions ([#599](https://github.com/awslabs/aws-lambda-powertools-python/issues/599))
1616
* **parser:** API Gateway WebSocket validation under check_message_id; plus some housekeeping ([#553](https://github.com/awslabs/aws-lambda-powertools-python/issues/553))
17+
* **feature-toggles:** correct cdk example ([#601](https://github.com/awslabs/aws-lambda-powertools-python/issues/601))
1718

1819
### Code Refactoring
1920

@@ -30,6 +31,7 @@ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) fo
3031
* **tracer:** update wording that it auto-disables on non-Lambda env
3132
* **feature-flags:** fix SAM infra, convert CDK to Python
3233
* **feature-flags:** fix sample feature name in evaluate method
34+
* **feature-flags:** add guidance when to use vs env vars vs parameters
3335
### Features
3436

3537
* **api-gateway:** add support for custom serializer ([#568](https://github.com/awslabs/aws-lambda-powertools-python/issues/568))

docs/utilities/feature_flags.md

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -110,59 +110,67 @@ The following sample infrastructure will be used throughout this documentation:
110110

111111
=== "CDK"
112112

113-
```python hl_lines="13-29 31 33 37 41 47"
114-
import json
115-
116-
import aws_cdk.aws_appconfig as appconfig
117-
from aws_cdk import core
113+
```python hl_lines="11-22 24 29 35 42 50"
114+
import json
115+
116+
import aws_cdk.aws_appconfig as appconfig
117+
from aws_cdk import core
118+
119+
120+
class SampleFeatureFlagStore(core.Construct):
121+
def __init__(self, scope: core.Construct, id_: str) -> None:
122+
super().__init__(scope, id_)
123+
124+
features_config = {
125+
"premium_features": {
126+
"default": False,
127+
"rules": {
128+
"customer tier equals premium": {
129+
"when_match": True,
130+
"conditions": [{"action": "EQUALS", "key": "tier", "value": "premium"}],
131+
}
132+
},
133+
},
134+
"ten_percent_off_campaign": {"default": True},
135+
}
118136

137+
self.config_app = appconfig.CfnApplication(
138+
self,
139+
id="app",
140+
name="product-catalogue",
141+
)
142+
self.config_env = appconfig.CfnEnvironment(
143+
self,
144+
id="env",
145+
application_id=self.config_app.ref,
146+
name="dev-env",
147+
)
148+
self.config_profile = appconfig.CfnConfigurationProfile(
149+
self,
150+
id="profile",
151+
application_id=self.config_app.ref,
152+
location_uri="hosted",
153+
name="features",
154+
)
155+
self.hosted_cfg_version = appconfig.CfnHostedConfigurationVersion(
156+
self,
157+
"version",
158+
application_id=self.config_app.ref,
159+
configuration_profile_id=self.config_profile.ref,
160+
content=json.dumps(features_config),
161+
content_type="application/json",
162+
)
163+
self.app_config_deployment = appconfig.CfnDeployment(
164+
self,
165+
id="deploy",
166+
application_id=self.config_app.ref,
167+
configuration_profile_id=self.config_profile.ref,
168+
configuration_version=self.hosted_cfg_version.ref,
169+
deployment_strategy_id="AppConfig.AllAtOnce",
170+
environment_id=self.config_env.ref,
171+
)
119172

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 = {
126-
"premium_features": {
127-
"default": False,
128-
"rules": {
129-
"customer tier equals premium": {
130-
"when_match": True,
131-
"conditions": [{
132-
"action": "EQUALS",
133-
"key": "tier",
134-
"value": "premium"
135-
}]
136-
}
137-
}
138-
},
139-
"ten_percent_off_campaign": {
140-
"default": True
141-
}
142-
}
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)
165-
```
173+
```
166174

167175
### Evaluating a single feature flag
168176

@@ -636,3 +644,11 @@ You can unit test your feature flags locally and independently without setting u
636644
# THEN
637645
assert flag == expected_value
638646
```
647+
648+
## Feature flags vs Parameters vs env vars
649+
650+
Method | When to use | Requires new deployment on changes | Supported services
651+
------------------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------- | -------------------------------------------------
652+
**[Environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html){target="_blank"}** | Simple configuration that will rarely if ever change, because changing it requires a Lambda function deployment. | Yes | Lambda
653+
**[Parameters utility](parameters.md)** | Access to secrets, or fetch parameters in different formats from AWS System Manager Parameter Store or Amazon DynamoDB. | No | Parameter Store, DynamoDB, Secrets Manager, AppConfig
654+
**Feature flags utility** | Rule engine to define when one or multiple features should be enabled depending on the input. | No | AppConfig

0 commit comments

Comments
 (0)