I am testing the throughput of writing to S3
from a python glue
shell job by using the upload_fileobj
function from the boto3
client. The input to this function is
Fileobj (a file-like object) -- A file-like object to upload. At a minimum, it must implement the read method, and must return bytes.
In order to have the test isolate just the throughput, as opposed to memory or CPU capabilities, I think the best way to use upload_file_object would be to pass an iterator
that produces N
bytes of the value 0
.
In python, how can a "file like object" be created from an iterator?
I'm looking for something of the form
from itertools import repeat
number_of_bytes = 1024 * 1024
zero_iterator = repeat(b'0', number_of_bytes)
file_like_object = something(zero_iterator) # fill in 'something'
Which would then be passed to boto3 for writing
session.client('s3').upload_fileobj(file_like_object, Bucket='my_bucket')
Thank you in advance for your consideration and response.