title: AWS Lambda image corrupted
body: <p>I'm having an issue with AWS Lambda where my resized images become corrupted every few uploads. I wrote a script that pulls from S3 and resizes it into 3 sizes into another bucket, mostly with filestreams.  Here is the code:</p>
  
  <p><a href="https://github.com/handonam/AWS-Resizer/blob/493ff10c317e7150d1ac040f54065083963a9c67/createThumbnails.js" rel="nofollow noreferrer">https://github.com/handonam/AWS-Resizer/blob/493ff10c317e7150d1ac040f54065083963a9c67/createThumbnails.js</a></p>
  
  <p>You can see the larger 512px upscaled file (the resized) along with the original (200px)</p>
  
  <p><a href="https://i.stack.imgur.com/aNXFg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aNXFg.png" alt="Resizing to 512px"></a></p>
  
  <p>And another resizing to 120px
  <a href="https://i.stack.imgur.com/DQLwx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DQLwx.png" alt="Resizing to 120px"></a></p>
  
  <p>My lambda consumption looks totally fine for the most part. It is set up on the same region with 768mb memory and 20s timeout.  The scripts execute around 2 seconds using 90/768mb for small images (like 500px wide), or 14 seconds @ 648/768mb on much larger images such as 2000px wide. But even for a small image, the resize dies on me.  If I abandon filestreams and just write to buffer (just like the <a href="http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html" rel="nofollow noreferrer">aws example</a>), then the image processing will end up with a buffer buffet, and lambda will use up way too many resources.</p>
  
  <p>Any guidance is appreciated!</p>