I just started learning and using S3, read the docs. Actually I didn't find anything to fetch the file into an object instead of downloading it from S3? if this could be possible, or I am missing something?
Actually I want to avoid additional IO after downloading the file.
I prefer this approach, equivalent to a previous answer:
But another approach could read the object into
StringIO
:You might be looking for the
get_object()
method of the boto3 S3 client:http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.get_object
This will get you a response object dictionary with member
Body
that is aStreamingBody
object, which you can use as normal file and call.read()
method on it. To get the entire content of the S3 object into memory you would do something like this:You could use
StringIO
and get file content from S3 usingget_contents_as_string
, like this: