The serverless-image-handler mono repository contains the source code and documentation for the image-handler and image-thumbs AWS Lambda functions.
The Image-handler is a solution Image Handler is a serverless image processing project built with Node.js 18 and the Sharp library. It allows you to dynamically scale images on the fly and serves them through AWS Lambda, AWS CloudFront, and AWS S3.
It aws originally forked from aws-solutions/serverless-image-handler repository, but has been heavily modified to suit our needs.
- Node.js v20.x or later
- Terraform
- Make / npm
- AWS credentials with sufficient permissions to read images from S3
To scale images dynamically on the fly, you can make HTTP requests to the AWS CloudFront distribution URL. The images are fetched from AWS S3, processed using Node.js 20 and Sharp / libvips, and then served through CloudFront.
Example URL:
https://images.t-online.de/4k_hdr.jpg
For more details see the Usage documentation.
The following environment variables are used by the image-handler:
Name | Description |
---|---|
AUTO_WEBP |
Flag if the AUTO WEBP feature should be enabled |
CORS_ENABLED |
Flag if CORS should be enabled |
CORS_ORIGIN |
CORS origin. |
SOURCE_BUCKETS |
S3 Bucket with source images |
To build the package run:
make FUNC=image-handler build
Run tests using the following Make command:
make npm/test
Deploy the infrastructure using Terraform with the following Make command:
make FUNC=image-handler tf
Image-thumbs is an implementation of thumbhash as a Rust AWS Lambda function URL providing a very compact representation of a placeholder for an image.
To build the package run:
make FUNC=thumbs build
See cargo lambda
# Terminal 1
cargo lambda watch
# Terminal 2
cargo lambda invoke --data-file apigw-request.json
To deploy the infrastructure run:
make FUNC=thumb tf