Can I use lambda to compress all images under a bucket?

Viewed 4130

Can I use lambda to compress images under a bucket? I can get the images under a particular bucket visa listObject. How do you compress these returns and write it in another bucket?

1 Answers

Yes, you can absolutely use lambda. Try this library: aws-lambda-image-compressor

AWS lambda function to compress and resize images

This is a Lambda Function which resizes/reduces images automatically. When an image is put on some AWS S3 bucket, this function will resize/reduce it and save it into a new bucket. I have used it in the past and I loved it.

Usage

  • edit lambda-config.js file and assign name, description, memory size, timeout of your lambda function.
  • edit .env file with your AWS access data
  • npm install
  • gulp deploy

You can also try this other library which is more popular in the crowd - aws-lambda-image

If you really want to create something of your own and want a good start.
I would recommend these 2 articles that explain it very well -

Image conversion using Amazon Lambda and S3 in Node.js

Automating Image Compression Using S3 & Lambda

If you are fine to use Amazon API Gateway then u can follow this AWS Compute Blog -
Resize Images on the Fly with Amazon S3, AWS Lambda, and Amazon API Gateway

Hope this was useful.

Related