-
Notifications
You must be signed in to change notification settings - Fork 432
feat(feature_flags): allow customers to bring their own boto3 client and session #4717
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
Merged
leandrodamascena
merged 9 commits into
aws-powertools:develop
from
adriantomas:adriantomas/app-config-store-client
Jul 10, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d53231d
feat: add `sdk_client` argument to AppConfigStore `__init__`
adriantomas a41dcbf
Merge branch 'develop' into adriantomas/app-config-store-client
adriantomas 32dcb12
style: fix typing
adriantomas 0c5be23
test: modify tests including sdk_client
adriantomas 0d91b0f
docs: add sdk_client to feature flags docs
adriantomas 8ff0453
Merge branch 'develop' into adriantomas/app-config-store-client
adriantomas 07c9f8f
Adding some small changes
leandrodamascena d747a57
Addressing Adrian's feedback
leandrodamascena 9492918
Merge branch 'develop' into adriantomas/app-config-store-client
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
examples/feature_flags/src/custom_boto_client_feature_flags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Any | ||
|
||
import boto3 | ||
|
||
from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
boto3_client = boto3.client("appconfigdata") | ||
|
||
app_config = AppConfigStore( | ||
environment="dev", | ||
application="product-catalogue", | ||
name="features", | ||
boto3_client=boto3_client, | ||
) | ||
|
||
feature_flags = FeatureFlags(store=app_config) | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext): | ||
apply_discount: Any = feature_flags.evaluate(name="ten_percent_off_campaign", default=False) | ||
|
||
price: Any = event.get("price") | ||
|
||
if apply_discount: | ||
# apply 10% discount to product | ||
price = price * 0.9 | ||
|
||
return {"price": price} |
29 changes: 29 additions & 0 deletions
29
examples/feature_flags/src/custom_boto_config_feature_flags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Any | ||
|
||
from botocore.config import Config | ||
|
||
from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
boto_config = Config(read_timeout=10, retries={"total_max_attempts": 2}) | ||
|
||
app_config = AppConfigStore( | ||
environment="dev", | ||
application="product-catalogue", | ||
name="features", | ||
boto_config=boto_config, | ||
) | ||
|
||
feature_flags = FeatureFlags(store=app_config) | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext): | ||
apply_discount: Any = feature_flags.evaluate(name="ten_percent_off_campaign", default=False) | ||
|
||
price: Any = event.get("price") | ||
|
||
if apply_discount: | ||
# apply 10% discount to product | ||
price = price * 0.9 | ||
|
||
return {"price": price} |
29 changes: 29 additions & 0 deletions
29
examples/feature_flags/src/custom_boto_session_feature_flags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Any | ||
|
||
import boto3 | ||
|
||
from aws_lambda_powertools.utilities.feature_flags import AppConfigStore, FeatureFlags | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
boto3_session = boto3.session.Session() | ||
|
||
app_config = AppConfigStore( | ||
environment="dev", | ||
application="product-catalogue", | ||
name="features", | ||
boto3_session=boto3_session, | ||
) | ||
|
||
feature_flags = FeatureFlags(store=app_config) | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext): | ||
apply_discount: Any = feature_flags.evaluate(name="ten_percent_off_campaign", default=False) | ||
|
||
price: Any = event.get("price") | ||
|
||
if apply_discount: | ||
# apply 10% discount to product | ||
price = price * 0.9 | ||
|
||
return {"price": price} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.