Giter Site home page Giter Site logo

blacho / serverless-image-resizing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amazon-archives/serverless-image-resizing

0.0 0.0 0.0 43.21 MB

ARCHIVED

License: Apache License 2.0

Shell 27.62% JavaScript 44.96% Makefile 12.16% Dockerfile 15.26%

serverless-image-resizing's Introduction

Archived

See https://github.com/awslabs/serverless-image-handler instead.

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

  1. Build the Lambda function

    The Lambda function uses sharp for image resizing which requires native extensions. In order to run on Lambda, it must be packaged on Amazon Linux. You can accomplish this in one of two ways:

    • Upload the contents of the lambda subdirectory to an Amazon EC2 instance running Amazon Linux and run npm install, or

    • Use the Amazon Linux Docker container image to build the package using your local system. This repo includes Makefile that will download Amazon Linux, install Node.js and developer tools, and build the extensions using Docker. Run make all.

  2. 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 version 1.11.19 or newer to be installed. Be sure to set your AWS credentials using aws configure

  3. 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/path/to/image.png
    • http://[BucketWebsiteHost]/90x90/path/to/image.png
    • http://[BucketWebsiteHost]/40x40/path/to/image.png

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

  4. (Optional) Restrict resize dimensions

    To restrict the dimensions the function will create, set the environment variable ALLOWED_DIMENSIONS to a string in the format (HEIGHT)x(WIDTH),(HEIGHT)x(WIDTH),....

    For example: 300x300,90x90,40x40.

License

This reference architecture sample is licensed under Apache 2.0.

serverless-image-resizing's People

Contributors

jpignata avatar jorrit avatar holygrolli avatar andybab avatar bigadev avatar freakingawesome avatar hyandell avatar grav avatar peterkuiper avatar levous avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.