Serverless Image Handler | 🚧 Feature request | 🐛 Bug Report | ❓ General Question
Note: If you want to use the solution without building from source, navigate to Solution Landing Page.
- Solution Overview
- Architecture Diagram
- AWS CDK and Solutions Constructs
- Customizing the Solution
- Collection of operational metrics
- External Contributors
- License
The Serverless Image Handler solution helps to embed images on websites and mobile applications to drive user engagement. It uses Sharp to provide high-speed image processing without sacrificing image quality. To minimize costs of image optimization, manipulation, and processing, this solution automates version control and provides flexible storage and compute options for file reprocessing.
This solution automatically deploys and configures a serverless architecture optimized for dynamic image manipulation. Images can be rendered and returned spontaneously. For example, an image can be resized based on different screen sizes by adding code on a website that leverages this solution to resize the image before being sent to the screen using the image. It uses Amazon CloudFront for global content delivery and Amazon Simple Storage Service (Amazon S3) for reliable and durable cloud storage.
For more information and a detailed deployment guide, visit the Serverless Image Handler solution page.
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.
AWS Cloud Development Kit (AWS CDK) and AWS Solutions Constructs make it easier to consistently create well-architected infrastructure applications. All AWS Solutions Constructs are reviewed by AWS and use best practices established by the AWS Well-Architected Framework. This solution uses the following AWS Solutions Constructs:
In addition to the AWS Solutions Constructs, the solution uses AWS CDK directly to create infrastructure resources.
- AWS Command Line Interface
- Node.js 14.x or later
git clone https://github.com/aws-solutions/serverless-image-handler.git
cd serverless-image-handler
export MAIN_DIRECTORY=$PWD
export REGION=aws-region-code # the AWS region to launch the solution (e.g. us-east-1)
export BUCKET_PREFIX=my-bucket-name # the bucket prefix, randomized name recommended
export BUCKET_NAME=$BUCKET_PREFIX-$REGION # the bucket name where customized code will reside
export SOLUTION_NAME=my-solution-name # the solution name
export VERSION=my-version # version number for the customized code
After making changes, run unit tests to make sure added customization passes the tests:
cd $MAIN_DIRECTORY/deployment
chmod +x run-unit-tests.sh
./run-unit-tests.sh
cd $MAIN_DIRECTORY/deployment
chmod +x build-s3-dist.sh
./build-s3-dist.sh $BUCKET_PREFIX $SOLUTION_NAME $VERSION
- Deploy the distributable to the Amazon S3 bucket in your account. Make sure you are uploading the files in
deployment/global-s3-assets
anddeployment/regional-s3-assets
to$BUCKET_NAME/$SOLUTION_NAME/$VERSION
. - Get the link of the solution template uploaded to your Amazon S3 bucket.
- Deploy the solution to your account by launching a new AWS CloudFormation stack using the link of the solution template in Amazon S3.
This solution collects anonymous operational metrics to help AWS improve the quality and features of the solution. For more information, including how to disable this capability, please see the implementation guide.
- @leviwilson for #117
- @rpong for #130
- @harriswong for #138
- @ganey for #139
- @browniebroke for #151, #152
- @john-shaffer for #158
- @toredash for #174, #195
- @lith-imad for #194
- @pch for #227
- @atrope for #201, #202
- @bretto36 for #182
- @makoncline for #255
- @frankenbubble for #302
- @guidev for #309
- @njtmead for #276
Copyright 2019-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0