Simple code for AWS Lambda to process images resize using NodeJS and AWS S3 trigger.
- Have an AWS account.
- Have NodeJS 8 installed locally to generate the node_modules.
- Create 2 buckets where one must have the sufix "resized", cause it will receive the resized images. I.e.
- my-image-bucket
- my-image-bucket-resized
- Create a Lambda function and give the access role containing AmazonS3FullAccess.
It will allow Lambda to read and write to your buckets.
- Add an S3 trigger to your Lambda.
- Point it to your bucket my-image-bucket.
- The
Event type
must be ObjectCreated.
Locally you need to generate the package that will be uploaded to aws. So in this project root folder:
- Install the node_modules:
npm install
- Generate a
lambda.tar.gz
file with containing the following files inside:
zip -r lambda node_modules index.js
-
Updalod the .zip file through your AWS Lambda panel and publish a new version.
-
Upload some image to your not resized bucket (i.e: images).
-
The image resized will appear inside the images-resized bucket in a folder resized-images.