@@ -249,13 +249,16 @@ def open(self) -> bool:
249
249
if self .is_opened ():
250
250
return True
251
251
252
- self .session = Session (
253
- aws_access_key_id = self .access_key if self .access_key != "" else None ,
254
- aws_secret_access_key = self .secret_key if self .secret_key != "" else None ,
255
- region_name = self .region ,
256
- )
257
-
252
+ # NOTE: Creating a client via a Session object does some unusual caching, which increases memory usage
253
+ # NOTE: each reload. Because of this, we only create Session object if the role is set, and in that case
254
+ # NOTE: the memory usage is expected to behave unusually. Sometime we should investigate this further.
258
255
if self .role != "" :
256
+ self .session = Session (
257
+ aws_access_key_id = self .access_key if self .access_key != "" else None ,
258
+ aws_secret_access_key = self .secret_key if self .secret_key != "" else None ,
259
+ region_name = self .region ,
260
+ )
261
+
259
262
# NOTE: The Session.set_credentials always creates a new Credentials object from the given keys.
260
263
# NOTE: The DeferredRefreshableCredentials class is a child of RefreshableCredentials which is a
261
264
# NOTE: child of the Credentials class.
@@ -271,10 +274,18 @@ def open(self) -> bool:
271
274
whoami = sts .get_caller_identity ().get ("Arn" )
272
275
self .logger .info (f"Using { whoami } to access the bucket" )
273
276
274
- self .client = self .session .client (
275
- service_name = "s3" ,
276
- endpoint_url = self .url if self .url != "" else None ,
277
- )
277
+ self .client = self .session .client (
278
+ service_name = "s3" ,
279
+ endpoint_url = self .url if self .url != "" else None ,
280
+ )
281
+ else :
282
+ self .client = client (
283
+ service_name = "s3" ,
284
+ endpoint_url = self .url if self .url != "" else None ,
285
+ aws_access_key_id = self .access_key if self .access_key != "" else None ,
286
+ aws_secret_access_key = self .secret_key if self .secret_key != "" else None ,
287
+ region_name = self .region ,
288
+ )
278
289
279
290
is_opened = False
280
291
try :
0 commit comments