Get objects
Load Python objects from an S3 bucket to Python
from io import BytesIO
import joblib
import boto3
def get_obj(key, bucket):
try:
# memory buffer
buffer = BytesIO()
# download object from S3-bucket
client = boto3.client('s3')
client.download_fileobj(
Fileobj=buffer,
Bucket=bucket,
Key=key,
)
# reset buffer position
buffer.seek(0)
# return object
if buffer is None:
return None
return joblib.load(buffer)
except:
passLast updated
Was this helpful?