Skip to content

LiArthur/serverless-image-resizing-cn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless Image Resizing

Description

Resizes images on the fly using Amazon S3, AWS Lambda, and Amazon API Gateway. Using a conventional URL structure and S3 static website hosting with redirection rules, requests for resized images are redirected to a Lambda function via API Gateway which will resize the image, upload it to S3, and redirect the requestor to the resized image. The next request for the resized image will be served from S3 directly.

Usage

  • Modify some files

    Modify 'REGION' to spacified region name in bin/deploy Modify 'ACCOUNT_ID' to your account id in bin/deploy and deploy/api.yaml

  • Deploy the CloudFormation stack

    Run bin/deploy to deploy the CloudFormation stack. It will create a temporary Amazon S3 bucket, package and upload the function, and create the Lambda function, Amazon API Gateway RestApi, and an S3 bucket for images via CloudFormation.

    The deployment script requires the [AWS CLI][cli] version 1.11.19 or newer to be installed.

  • Modify code package

    Download Lambda package from console, and hard code bucket name and url in index.js, because environment variable is not available.

  • Test the function

    Upload an image to the S3 bucket and try to resize it via your web browser to different sizes, e.g. with an image uploaded in the bucket called image.png:

    • http://[BucketWebsiteHost]/300x300/image.png
    • http://[BucketWebsiteHost]/90x90/image.png
    • http://[BucketWebsiteHost]/40x40/image.png

    You can find the BucketWebsiteUrl in the table of outputs displayed on a successful invocation of the deploy script.

Note: If you create the Lambda function yourself, make sure to select Node.js version 6.10.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published