forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimebased_feature.py
More file actions
46 lines (37 loc) · 1.56 KB
/
Copy pathtimebased_feature.py
File metadata and controls
46 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags
from aws_lambda_powertools.utilities.typing import LambdaContext
app_config = AppConfigStore(environment="dev", application="product-catalogue", name="features")
feature_flags = FeatureFlags(store=app_config)
def lambda_handler(event: dict, context: LambdaContext):
"""
This feature flag is enabled under the following conditions:
- The request payload contains a field 'tier' with the value 'premium'.
- If the current day is either Saturday or Sunday in America/New_York timezone.
Rule condition to be evaluated:
"conditions": [
{
"action": "EQUALS",
"key": "tier",
"value": "premium"
},
{
"action": "SCHEDULE_BETWEEN_DAYS_OF_WEEK",
"key": "CURRENT_DAY_OF_WEEK",
"value": {
"DAYS": [
"SATURDAY",
"SUNDAY"
],
"TIMEZONE": "America/New_York"
}
}
]
"""
# Get customer's tier from incoming request
ctx = {"tier": event.get("tier", "standard")}
# Checking if the weekend premum discount is enable
weekend_premium_discount = feature_flags.evaluate(name="weekend_premium_discount", default=False, context=ctx)
if weekend_premium_discount:
# Enable special discount on weekend for premium users:
return {"message": "The weekend premium discount is enabled."}
return {"message": "The weekend premium discount is not enabled."}