node.js - AWS Lambda image corrupted

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:

You can see the larger 512px upscaled file (the resized) along with the original (200px)

Resizing to 512px

And another resizing to 120px Resizing to 120px

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 aws example), then the image processing will end up with a buffer buffet, and lambda will use up way too many resources.

Any guidance is appreciated!

1 Answer

  1. Justin- Reply


    What's the chance your code is not threadsafe? i.e., some concurrent runs of the script collide? The corrupted file you show looks like it could have incorrect dimensions.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>