title: How to use botocore.response.StreamingBody as stdin PIPE
body: <p>I want to pipe large video files from AWS S3 into <code>Popen</code>'s <code>stdin</code>, which is from Python's point of view a 'file-like object'. 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 <code>Popen pipe</code>.</p>
  <p>Update: I put together a <a href="https://github.com/mslinn/pvideoShared2" rel="nofollow noreferrer">short program</a> that invokes StreamingBody.read(amt=chunk_size) based on a comment. The program reads some of the input file (an mp4 video) and gets stuck, possibly because the consumer of the data (ffmpeg) does not actually run, or maybe its STDIN buffer fills and the whole mess grinds to a halt?</p>
  <p>I can access a file in an S3 bucket:</p>
  <pre class="lang-py prettyprint-override"><code>import boto3
  s3 = boto3.resource('s3')
  response = s3.Object(bucket_name=bucket, key=key).get()
  body = response['Body']  
  </code></pre>
  <p><code>body</code> is a <code>botocore.response.StreamingBody</code> which looks like this:</p>
  <pre><code>{
    u'Body': &lt;botocore.response.StreamingBody object at 0x00000000042EDAC8&gt;,
    u'AcceptRanges': 'bytes', 
    u'ContentType': 'video/mp4', 
    'ResponseMetadata': {
      'HTTPStatusCode': 200, 
      'HostId': 'aAUs3IdkXP6vPGwauv6/USEBUWfxxVeueNnQVAm4odTkPABKUx1EbZO/iLcrBWb+ZiyqmQln4XU=', 
      'RequestId': '6B306488F6DFEEE9'
    }, 
    u'LastModified': datetime.datetime(2015, 3, 1, 1, 32, 58, tzinfo=tzutc()),
    u'ContentLength': 393476644, 
    u'ETag': '&quot;71079d637e9f14a152170efdf73df679&quot;', 
    u'Metadata': {'cb-modifiedtime': 'Sun, 01 Mar 2015 01:27:52 GMT'}}
  </code></pre>
  <p>I intend to use <code>body</code> something like this:</p>
  <pre><code>from subprocess import Popen, PIPE
  Popen(cmd, stdin=PIPE, stdout=PIPE).communicate(input=body)[0]
  </code></pre>
  <p>But of course <code>body</code> needs to be converted into a file-like object. The question is how?</p>