This application can be deploy on lambda to compress image from S3 bucket and place it in another S3 bucket.
- Support latest Nodejs (18.x). There are many sample on the internet but not support latest nodejs.
- Auto delete original image once the resource been moved to compressed bucket
- Cloudfront fallback (no need to worry the delay between compress and display to end user)
- Fallback when unsupport file occoured (e.g. when there are non-image file been send to lambda, system will skip compress and move original file to compressed bucket directly.)
- Compress file
- Create a role with
S3
andLambda
full access
[MAKE SURE YOUR LAMBDA AND S3 ARE IN SAME REGION]
- Attach the previous role to the lambda function
- Upload deploy.zip to lambda
- On configuration page > Environment variables, add
COMPRESSED_BUCKET
andUNCOMPRESSED_BUCKET
with your bucket name - On configuration page > General configuration, Change Memory to 1024MB, Storage to 1024MB and Timeout to 0 min 30 sec.
[MAKE SURE YOUR LAMBDA AND S3 ARE IN SAME REGION]
- Create on bucket to place original files
- Create another bucket to place compressed files
- Create a cloudfront distributions
- Create two origin pointing to two previous created buckets
- Create one origin group, pointing to two origin (p.s. bucket )
And upload to lambda
cd lambda-compress-image-node18.x
zip -r deploy.zip .