Skip to content

wchaws/serverless-image-handler

 
 

Repository files navigation

Important Notice: Due to a change in the AWS Lambda execution environment, Serverless Image Handler v3 deployments are functionally broken. To address the issue we have released minor version update v3.1.1. We recommend all users of v3 to run cloudformation stack update with v3.1.1. Additionally, we suggest you to look at v5 of the solution and migrate to v5 if it addresses all of your use cases.

AWS Serverless Image Handler Lambda wrapper for SharpJS

A solution to dynamically handle images on the fly, utilizing Sharp (https://sharp.pixelplumbing.com/en/stable/). Published version, additional details and documentation are available here: https://aws.amazon.com/solutions/serverless-image-handler/

Note: it is recommended to build the application binary on Amazon Linux.

On This Page

Architecture Overview

Architecture

The AWS CloudFormation template deploys an Amazon CloudFront distribution, Amazon API Gateway REST API, and an AWS Lambda function. Amazon CloudFront provides a caching layer to reduce the cost of image processing and the latency of subsequent image delivery. The Amazon API Gateway provides endpoint resources and triggers the AWS Lambda function. The AWS Lambda function retrieves the image from the customer's Amazon Simple Storage Service (Amazon S3) bucket and uses Sharp to return a modified version of the image to the API Gateway. Additionally, the solution generates a CloudFront domain name that provides cached access to the image handler API.

Note: From v5.0, all AWS CloudFormation template resources are created be AWS CDK and AWS Solutions Constructs. Since the AWS CloudFormation template resources have the same logical ID comparing to v4.x, it makes the solution upgradable mostly from v4.x to v5.

Creating a custom build

The solution can be deployed through the CloudFormation template available on the solution home page. To make changes to the solution, download or clone this repo, update the source code and then run the deployment/build-s3-dist.sh script to deploy the updated Lambda code to an Amazon S3 bucket in your account.

Prerequisites:

1. Clone the repository

git clone https://github.com/awslabs/serverless-image-handler.git

2. Run unit tests for customization

Run unit tests to make sure added customization passes the tests:

cd ./deployment
chmod +x ./run-unit-tests.sh
./run-unit-tests.sh

3. Declare environment variables

export REGION=aws-region-code # the AWS region to launch the solution (e.g. us-east-1)
export DIST_OUTPUT_BUCKET=my-bucket-name # bucket where customized code will reside
export SOLUTION_NAME=my-solution-name # the solution name
export VERSION=my-version # version number for the customized code

4. Create an Amazon S3 Bucket

The CloudFormation template is configured to pull the Lambda deployment packages from Amazon S3 bucket in the region the template is being launched in. Create a bucket in the desired region with the region name appended to the name of the bucket.

aws s3 mb s3://$DIST_OUTPUT_BUCKET-$REGION --region $REGION

5. Create the deployment packages

Build the distributable:

chmod +x ./build-s3-dist.sh
./build-s3-dist.sh $DIST_OUTPUT_BUCKET $SOLUTION_NAME $VERSION

Deploy the distributable to the Amazon S3 bucket in your account:

aws s3 sync ./regional-s3-assets/ s3://$DIST_OUTPUT_BUCKET-$REGION/$SOLUTION_NAME/$VERSION/ --acl bucket-owner-full-control
aws s3 sync ./global-s3-assets/ s3://$DIST_OUTPUT_BUCKET-$REGION/$SOLUTION_NAME/$VERSION/ --acl bucket-owner-full-control

6. Launch the CloudFormation template.

  • Get the link of the serverless-image-handler.template uploaded to your Amazon S3 bucket.
  • Deploy the Serverless Image Handler solution to your account by launching a new AWS CloudFormation stack using the S3 link of the serverless-image-handler.template.

External Contributors


License

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0

About

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 51.0%
  • TypeScript 42.7%
  • HTML 2.7%
  • Python 1.3%
  • Shell 1.1%
  • Makefile 0.6%
  • Other 0.6%