Skip to content

Commit 222a56e

Browse files
nadiayametrizable
authored andcommitted
feature: Use boto3 DEFAULT_SESSION when no boto3 session specified. (aws#1545)
1 parent 9b32c19 commit 222a56e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/sagemaker/session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _initialize(self, boto_session, sagemaker_client, sagemaker_runtime_client):
123123
Creates or uses a boto_session, sagemaker_client and sagemaker_runtime_client.
124124
Sets the region_name.
125125
"""
126-
self.boto_session = boto_session or boto3.Session()
126+
self.boto_session = boto_session or boto3.DEFAULT_SESSION or boto3.Session()
127127

128128
self._region_name = self.boto_session.region_name
129129
if self._region_name is None:

tests/unit/test_session.py

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ def boto_session():
5252
return boto_mock
5353

5454

55+
@patch("boto3.DEFAULT_SESSION")
56+
def test_default_session(boto3_default_session):
57+
sess = Session()
58+
assert sess.boto_session is boto3_default_session
59+
60+
61+
@patch("boto3.Session")
62+
def test_new_session_created(boto3_session):
63+
sess = Session()
64+
assert sess.boto_session is boto3_session.return_value
65+
66+
5567
def test_process(boto_session):
5668
session = Session(boto_session)
5769

0 commit comments

Comments
 (0)