title: how to stream and write to a file in s3 in node js?
body: <p>running this code locally.here someApi.getData returns an array of items. I am iterating through the data and streaming it to the file. I want to run this in aws lambda now , how can i stream it to a text file in s3?</p>
  <pre><code>const fs = require('fs')
  const writeStream = fs.createWriteStream('test.txt');
  const pathName = writeStream.path;
  
  someApi.GetData('http://example.com')
  .then(function(data){
     data.forEach(val =&gt; writeStream.write(val));
     writeStream.on('finish', ()=&gt; {console.log('success')});
     writeStream.on('error', ()=&gt; {console.log('error')});
     writeStream.end();
  })
  .catch(error =&gt; console.log(error));
  </code></pre>