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

Allow to define client_config when using boto3.setup_default_session #4244

Open
1 of 2 tasks
Et7f3 opened this issue Aug 21, 2024 · 1 comment
Open
1 of 2 tasks

Allow to define client_config when using boto3.setup_default_session #4244

Et7f3 opened this issue Aug 21, 2024 · 1 comment
Labels
feature-request This issue requests a feature. p3 This is a minor priority issue

Comments

@Et7f3
Copy link

Et7f3 commented Aug 21, 2024

Describe the feature

Be able to define default client_config when setting up a default session.

Use Case

I have a code pattern in multiple places, so I had to make a wrapper:

    def create_aws_client(service: str) -> BaseClient:
        return boto3.client(
            service_name=service,
            aws_access_key_id="My AWS_ACCESS_KEY_ID",
            aws_secret_access_key="My AWS_SECRET_ACCESS_ID",
            config=Config(proxies={"https": "My HTTPS_PROXY"})
        )

I see that boto3.setup_default_session can help by setting globally aws_access_key_id and aws_secret_access_key but it doesn't seems to have a parameter for config.

boto3/boto3/__init__.py

Lines 27 to 34 in bd077f3

def setup_default_session(**kwargs):
"""
Set up a default session, passing through any parameters to the session
constructor. There is no need to call this unless you wish to pass custom
parameters, because a default session will be created for you.
"""
global DEFAULT_SESSION
DEFAULT_SESSION = Session(**kwargs)
because it forward to Session constructor that just doesn't have such settings:

boto3/boto3/session.py

Lines 49 to 57 in bd077f3

def __init__(
self,
aws_access_key_id=None,
aws_secret_access_key=None,
aws_session_token=None,
region_name=None,
botocore_session=None,
profile_name=None,
):

Proposed Solution

Workaround I use (but would like to avoid)

session = botocore.session.get_session()
session.set_default_client_config(Config(proxies={"https": "My HTTPS_PROXY"}))
boto3.setup_default_session(
  aws_access_key_id="My AWS_ACCESS_KEY_ID",
  aws_secret_access_key="My AWS_SECRET_ACCESS_ID",
  botocore_session=session,
)

Proposed fix:

    def __init__(
        self,
        aws_access_key_id=None,
        aws_secret_access_key=None,
        aws_session_token=None,
        region_name=None,
        botocore_session=None,
        profile_name=None,
+      client_config=None,
    ):
        if botocore_session is not None:
            self._session = botocore_session
        else:
            # Create a new default session
            self._session = botocore.session.get_session()
+          if client_config is not None:
+            self._session.set_default_client_config(client_config)

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

SDK version used

1.35.2

Environment details (OS name and version, etc.)

not relevant

@Et7f3 Et7f3 added feature-request This issue requests a feature. needs-triage This issue or PR still needs to be triaged. labels Aug 21, 2024
@tim-finnigan tim-finnigan self-assigned this Aug 27, 2024
@tim-finnigan
Copy link
Contributor

Thanks for the feature request — others can 👍 your post if also interested in this and we can track discussion here.

@tim-finnigan tim-finnigan added p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Aug 27, 2024
@tim-finnigan tim-finnigan removed their assignment Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This issue requests a feature. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

2 participants