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)
And another 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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With