Solution
import io
import boto3
import docx
BUCKET_NAME = "my-bucket"
def main():
s3 = boto3.resource("s3")
bucket = s3.Bucket(BUCKET_NAME)
object_in_s3 = bucket.Object("test.docx")
object_as_streaming_body = object_in_s3.get()["Body"]
print(f"Type of object_as_streaming_body: {type(object_as_streaming_body)}")
object_as_bytes = object_as_streaming_body.read()
print(f"Type of object_as_bytes: {type(object_as_bytes)}")
# Now we use BytesIO to create a file-like object from our byte-stream
object_as_file_like = io.BytesIO(object_as_bytes)
# Et voila!
document = docx.Document(docx=object_as_file_like)
print(document.paragraphs)
if __name__ == "__main__":
main()
$ python test.py
Type of object_as_streaming_body:
Type of object_as_bytes:
[]