Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

https://github.com/handonam/AWS-Resizer/blob/493ff10c317e7150d1ac040f54065083963a9c67/createThumbnails.js

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!

like image 384
Handonam Avatar asked Mar 11 '16 07:03

Handonam


1 Answers

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.

like image 161
some ideas Avatar answered Oct 22 '22 02:10

some ideas