title: Use Read Stream from AWS S3 getObject to read and upload to a different bucket
body: <p>I am trying to read a file from a third party AWS S3 bucket which is in a <code>.gz</code> format. I need to process the data in the file and upload the file to our own S3 Bucket.</p>
  <p>For reading the file, I am creating a readStream from S3.getBucket as shown below:</p>
  <pre><code>const fileStream = externalS3.getObject({Bucket: &lt;bucket-name&gt;, Key: &lt;key&gt;}).createReadStream();
  </code></pre>
  <p>For making the code more efficient, I am planning to use the same <code>fileStream</code> for both processing the contents and uploading to our own S3. I have the code below, which does not  upload the file to the internal S3 bucket.</p>
  <pre><code>import Stream from &quot;stream&quot;;
  
  const uploadStream = fileStream.pipe(new stream.PassThrough());
  const readStream = fileStream.pipe(new stream.PassThrough());
  
  await internalS3.upload({Bucket:&lt;bucket-name&gt;, Key: &lt;key&gt;, Body: uploadStream})
  .on(&quot;httpUploadProgress&quot;, progress =&gt; {console.log(progress)})
  .on(&quot;error&quot;, error =&gt; {console.log(error)})
  .promise();
  
  readStream.pipe(createGunzip())
  .on(&quot;error&quot;, err =&gt;{console.log(err)})
  .pipe(JSONStream.parse())
  .on(&quot;data&quot;, data =&gt; {console.log(data)});
  </code></pre>
  <p>However, the code below successfully uploads the file to the internal s3 bucket.</p>
  <pre><code>const uploadStream = fileStream.pipe(new stream.PassThrough());
  
  
  await internalS3.upload({Bucket:&lt;bucket-name&gt;, Key: &lt;key&gt;, Body: uploadStream})
  .on(&quot;httpUploadProgress&quot;, progress =&gt; {console.log(progress)})
  .on(&quot;error&quot;, error =&gt; {console.log(error)})
  .promise();
  </code></pre>
  <p>What am I doing wrong here ?</p>
  <p>NOTE: If I use separate <code>fileStream</code>s to upload and read data, it works fine. However, I need to achieve this using the same fileStream.</p>