Skip to content

Commit

Permalink
WIP: corrected the s3bucket dataplug to use session to create s3 client
Browse files Browse the repository at this point in the history
  • Loading branch information
vlianCMU committed Mar 28, 2024
1 parent 2ab2ed4 commit e988b44
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions sdt_dask/dataplugs/S3Bucket_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ def __init__(self, bucket_name):
"""
self.bucket_name = bucket_name

def _create_s3_client(self):
# Creating a new session for each call to ensure thread safety
session = boto3.session.Session()
s3_client = session.client('s3')
return s3_client

def _pull_data(self, key):

s3_client = boto3.client('s3')
print(f"Loading file from S3 bucket: {key}...")

s3_client = self._create_s3_client()
obj = s3_client.get_object(Bucket=self.bucket_name, Key=key)

# Assume file is CSV
Expand Down Expand Up @@ -58,7 +63,7 @@ def _pull_keys(self) -> list:
"""
KEYS = []

s3_client = boto3.client('s3')
s3_client = self._create_s3_client()
objects = s3_client.list_objects_v2(Bucket=self.bucket_name)

if 'Contents' in objects:
Expand Down

0 comments on commit e988b44

Please sign in to comment.