@@ -14,7 +14,7 @@ Feature flags are used to modify behaviour without changing the application's co
14
14
15
15
** Static flags** . Indicates something is simply ` on ` or ` off ` , for example ` TRACER_ENABLED=True ` .
16
16
17
- ** Dynamic flags** . Indicates something can have varying states, for example enable a premium feature for customer X not Y.
17
+ ** Dynamic flags** . Indicates something can have varying states, for example enable a list of premium features for customer X not Y.
18
18
19
19
???+ tip
20
20
You can use [ Parameters utility] ( parameters.md ) for static flags while this utility can do both static and dynamic feature flags.
@@ -380,6 +380,71 @@ You can use `get_enabled_features` method for scenarios where you need a list of
380
380
}
381
381
```
382
382
383
+ ### Beyond boolean feature flags
384
+
385
+ ???+ info "When is this useful?"
386
+ You might have a list of features to unlock for premium customers, unlock a specific set of features for admin users, etc.
387
+
388
+ Feature flags can return any JSON values when ` boolean_type ` parameter is set to ` False ` . These can be dictionaries, list, string, integers, etc.
389
+
390
+
391
+ === "app.py"
392
+
393
+ ```python hl_lines="3 9 13 16 18"
394
+ from aws_lambda_powertools.utilities.feature_flags import FeatureFlags, AppConfigStore
395
+
396
+ app_config = AppConfigStore(
397
+ environment="dev",
398
+ application="product-catalogue",
399
+ name="features"
400
+ )
401
+
402
+ feature_flags = FeatureFlags(store=app_config)
403
+
404
+ def lambda_handler(event, context):
405
+ # Get customer's tier from incoming request
406
+ ctx = { "tier": event.get("tier", "standard") }
407
+
408
+ # Evaluate `has_premium_features` base don customer's tier
409
+ premium_features: list[str] = feature_flags.evaluate(name="premium_features",
410
+ context=ctx, default=False)
411
+ for feature in premium_features:
412
+ # enable premium features
413
+ ...
414
+ ```
415
+
416
+ === "event.json"
417
+
418
+ ```json hl_lines="3"
419
+ {
420
+ "username": "lessa",
421
+ "tier": "premium",
422
+ "basked_id": "random_id"
423
+ }
424
+ ```
425
+ === "features.json"
426
+
427
+ ```json hl_lines="3-4 7"
428
+ {
429
+ "premium_features": {
430
+ "boolean_type": false,
431
+ "default": [],
432
+ "rules": {
433
+ "customer tier equals premium": {
434
+ "when_match": ["no_ads", "no_limits", "chat"],
435
+ "conditions": [
436
+ {
437
+ "action": "EQUALS",
438
+ "key": "tier",
439
+ "value": "premium"
440
+ }
441
+ ]
442
+ }
443
+ }
444
+ }
445
+ }
446
+ ```
447
+
383
448
## Advanced
384
449
385
450
### Adjusting in-memory cache
@@ -436,11 +501,11 @@ A feature can simply have its name and a `default` value. This is either on or o
436
501
``` json hl_lines="2-3 5-7" title="minimal_schema.json"
437
502
{
438
503
"global_feature" : {
439
- "default" : True
504
+ "default" : true
440
505
},
441
506
"non_boolean_global_feature" : {
442
507
"default" : {"group" : " read-only" },
443
- "boolean_type" : False
508
+ "boolean_type" : false
444
509
},
445
510
}
446
511
```
0 commit comments