Saving an object to CSV directly to S3

Viewed 19
1 Answers

Docs with example of sending existing file: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html

If you have a file content in a string, use BytesIO to make it a file-like object:

s3 = boto3.resource("s3")
bucket = s3.Bucket(bucket_name)

stream = io.BytesIO(my_str_data.encode())  # boto3 only allows to bytes data, so we need to encode
filename = "filename_here"
bucket.upload_fileobj(stream, filename)

Since you said you already have a file-like object, make sure it's bytes file-like object and just put in in place of stream

Related