Upload objects
Upload Python objects from Python to an S3 bucket
from io import BytesIO
import joblib
import boto3
def upload_obj(key, obj, bucket):
# dump object into a memory buffer
buffer = BytesIO()
joblib.dump(obj, buffer)
# reset buffer position before upload
buffer.seek(0)
# upload object to S3-bucket
client = boto3.client('s3')
client.upload_fileobj(
Fileobj=buffer,
Bucket=bucket,
Key=key
)Last updated
Was this helpful?