Skip to content
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

feat(feature_flags): allow customers to bring their own boto3 client and session #4717

Merged
merged 9 commits into from
Jul 10, 2024
Merged

feat(feature_flags): allow customers to bring their own boto3 client and session #4717

merged 9 commits into from
Jul 10, 2024

Conversation

adriantomas
Copy link
Contributor

@adriantomas adriantomas commented Jul 9, 2024

Issue number: #4728

Summary

This pull request adds an argument to be able to send a boto3 client from AppConfigData to the AppConfigStore initializer.

Changes

Please provide a summary of what's being changed

  • Adds an argument to send a boto3 client of AppConfigData in the initialization of the AppConfigStore.
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}

User experience

Please share what the user experience looks like before and after this change

Enables the following:

  • Reuse the AppConfigData boto3 client for other uses not related to the AppConfigStore and allow to comply with a best practice.
  • Use the AWS AppConfig Agent Lambda extension, changing the endpoint_url argument of the client.
  • Create infrastructure mocks that point to local emulators such as LocalStack or moto.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 9, 2024
@adriantomas adriantomas marked this pull request as ready for review July 9, 2024 13:44
@adriantomas adriantomas requested a review from a team as a code owner July 9, 2024 13:44
@leandrodamascena
Copy link
Contributor

Hello @adriantomas! What a great discovery to improve this utility!

Do you mind creating an issue to link here? And I think maybe there are some tests left, right?

@adriantomas
Copy link
Contributor Author

Hello @adriantomas! What a great discovery to improve this utility!

Do you mind creating an issue to link here? And I think maybe there are some tests left, right?

Sure, let me take a look ;)

@leandrodamascena leandrodamascena changed the title feat: add sdk_client argument to AppConfigStore __init__ feat(feature_flags): allow customer to bring their own SDK client Jul 9, 2024
@leandrodamascena leandrodamascena changed the title feat(feature_flags): allow customer to bring their own SDK client feat(feature_flags): allow customers to bring their own SDK client Jul 9, 2024
@github-actions github-actions bot added the feature New feature or functionality label Jul 9, 2024
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels Jul 10, 2024
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 10, 2024
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.43%. Comparing base (14b44ce) to head (9492918).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4717   +/-   ##
========================================
  Coverage    96.42%   96.43%           
========================================
  Files          223      223           
  Lines        10756    10757    +1     
  Branches      2001     2001           
========================================
+ Hits         10372    10373    +1     
  Misses         270      270           
  Partials       114      114           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 10, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jul 10, 2024
@leandrodamascena
Copy link
Contributor

Hello @adriantomas! I've made a few changes to this PR to adjust some minor things. Here's a summary of what I've done:

1 - I've changed the name from sdk_client to boto3_client, as this is the standard we're using.
2 - I also added 2 new boto3_session and boto_config parameters, as this is how we're using them now.
3 - I've discouraged the use of sdk_config, as we no longer use this name. I didn't introduce any breaking changes for existing code, but I've removed it from the documentation to prevent further use.
4 - I've made some adjustments to the configuration to bring more clarity.

Please let me know your thoughts. We want to include this change in our tomorrow's release.

Thanks a lot for working on this PR.

@leandrodamascena leandrodamascena changed the title feat(feature_flags): allow customers to bring their own SDK client feat(feature_flags): allow customers to bring their own boto3 client and session Jul 10, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jul 10, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jul 10, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jul 10, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jul 10, 2024
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this PR @adriantomas! APPROVED!! 🚀

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jul 10, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jul 10, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jul 10, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jul 10, 2024
@leandrodamascena leandrodamascena merged commit 10d551c into aws-powertools:develop Jul 10, 2024
17 checks passed
@adriantomas adriantomas deleted the adriantomas/app-config-store-client branch July 10, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: allow to provide an appconfigdata client in the AppConfigStore
2 participants