From c8ea710edd6bd9e5aaff1128209c59bbc8bc636f Mon Sep 17 00:00:00 2001 From: "mr.Shu" Date: Tue, 19 May 2020 19:34:52 +0200 Subject: [PATCH] _utils: Make sure boto3's default session is used * Currently `awswrangler` ensures that at least some boto3 Session is used when it calls AWS resources. However, since it creates a `boto3.Session()` when non-null boto3 Session is passed as a parameter, it completely sidesteps the ability of the user to set parameters to the boto3 session that gets used by default (via the `boto3.setup_default_session` function). * This commit ensures that the `ensure_session` function uses boto3's default session (reachable via `boto3._get_default_session()`) which then also allows `awswrangler` users to set default parameters of the boto3 Session it uses by default via `boto3.setup_default_session()`. Signed-off-by: mr.Shu --- awswrangler/_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/awswrangler/_utils.py b/awswrangler/_utils.py index 20c9f27ec..c774c2e9c 100644 --- a/awswrangler/_utils.py +++ b/awswrangler/_utils.py @@ -18,7 +18,9 @@ def ensure_session(session: Optional[boto3.Session] = None) -> boto3.Session: """Ensure that a valid boto3.Session will be returned.""" if session is not None: return session - return boto3.Session() + # Ensure the boto3's default session is used so that its parameters can be + # set via boto3.setup_default_session() + return boto3._get_default_session() # pylint: disable=protected-access def client(service_name: str, session: Optional[boto3.Session] = None) -> boto3.client: