Skip to content

stroeer/serverless-image-handler

 
 

Repository files navigation

Serverless Image Handler Readme

The serverless-image-handler mono repository contains the source code and documentation for the image-handler and image-thumbs AWS Lambda functions.

Table of Contents

Architecture

Architecture

Image Handler

Overview

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.

Prerequisites

  • Node.js v20.x or later
  • Terraform
  • Make / npm
  • AWS credentials with sufficient permissions to read images from S3

Usage

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.

Environment variables

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

Building

To build the package run:

make FUNC=image-handler build

Testing

Run tests using the following Make command:

make npm/test

Infrastructure deployment

Deploy the infrastructure using Terraform with the following Make command:

make FUNC=image-handler tf

Image Thumbs

Overview

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.

Prerequisites

Building

To build the package run:

make FUNC=thumbs build

Test / Invoke

See cargo lambda

# Terminal 1
cargo lambda watch
# Terminal 2
cargo lambda invoke --data-file apigw-request.json

Infrastructure deployment

To deploy the infrastructure run:

make FUNC=thumb tf

About

A solution to dynamically handle images on the fly, utilizing SharpJS

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • TypeScript 83.7%
  • HCL 11.4%
  • Rust 2.7%
  • Makefile 2.2%