How I Automated Image Resizing with AWS Lambda
At work, I built an image resizing pipeline using AWS Lambda + S3 to address image upload performance issues.
1. Triggered when an image is uploaded to an S3 bucket
2. The Lambda function resizes the image using the Sharp library
3. Saves the result to another S3 bucket
4. Caches via CloudFront
Tip: Allocate at least 1024MB of memory to Lambda to prevent Sharp from crashing. Also, I recommend setting up Provisioned Concurrency to handle cold starts.
Performance: Processes a 3MB image down to 500KB in under 5 seconds. Costs are also low, around $2–$3 per month.
7 answers
Oh, this is nice. I was also thinking about trying image processing with Lambda.
But doesn't Sharp often crash on cold start? I'm a bit worried about that.
3MB in 5 seconds is pretty fast. But with 1024MB of memory, it seems like the cost might be a bit high.
Agreed. I use it similarly too, and without Provisioned Concurrency, the first request is annoyingly slow.
Isn't this old news? These days, you can solve cold starts with things like Lambda SnapStart.
I tried something similar before, and 1536MB was actually more stable than 1024MB. Sharp tends to eat up a lot of memory.
Still, 2 to 3 dollars is cheap. I should give it a try too.