How to Use botocore.response.StreamingBody as stdin PIPE
See original GitHub issueI want to pipe large video files from AWS S3 into Popen
’s stdin
. This code runs as an AWS Lambda function, so these files won’t fit in memory or on the local file system. Also, I don’t want to copy these huge files anywhere, I just want to stream the input, process on the fly, and stream the output. I’ve already got the processing and streaming output bits working. The problem is how to obtain an input stream as a Popen pipe
.
I can access a file in an S3 bucket:
import boto3
s3 = boto3.resource('s3')
response = s3.Object(bucket_name=bucket, key=key).get()
body = response['Body']
body
is a botocore.response.StreamingBody
. I intend to use body
something like this:
from subprocess import Popen, PIPE
Popen(cmd, stdin=PIPE, stdout=PIPE).communicate(input=body)[0]
But of course body
needs to be converted into a file-like object. The question is how?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:38 (3 by maintainers)
Top Results From Across the Web
How to use botocore.response.StreamingBody as stdin PIPE
1 Answer 1 · 5. Calling read() loads the entire video (hundreds of MB) into RAM. · 1. @MikeSlinn StreamingBody. · 1. I...
Read more >Developers - How to Use botocore.response.StreamingBody as ...
How to Use botocore.response.StreamingBody as stdin PIPE.
Read more >Response Reference — botocore 1.29.34 documentation - AWS
class botocore.response. StreamingBody (raw_stream ... Wrapper class for an http response body. ... Close the underlying http response stream.
Read more >boto3 streamingBody to BytesIO - Serious Autonomous Vehicles
the following discussion is really really helpful: boto3 issue #426: how to use botocore.response.StreamingBody as stdin PIPE.
Read more >Process Files through Unix pipeline in AWS Lambda - Medium
First, we obtain the input data stream using boto3 : import boto3 ... stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=bufsize).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not sure if this helps, but I struggled with a similar issue streaming from boto3:s3 to flask output stream. Some sample code here, may help you:
I wish it were so simple. I must have dumped at least 30 hours into this problem, and I’ve tried a variety of approaches. I’ve tried the AWS & Python communities on StackOverflow but got no response. I think this issue requires too much setup for a generic Python programmer to address.
I’m sure this will be an often-repeated question, I’m just the first to hit it. I think someone from AWS should take it up.
For my part, I’ve got a broken product in production as a result of this issue. I am willing to pay cash money for a fix.