Giter VIP home page Giter VIP logo

aws-s3-lambda-thumbnail-generator's Introduction

aws-s3-lambda-thumbnail-generator

An Amazon Web Services Lambda function that generates thumbnails from images uploaded to AWS S3.

Usage

If you have a platform (website, mobile app, etc...) with a user-generated content where users upload images to Amazon's S3 and you need to automatically generate thumbnails, then this is a great solution that can be integrated in few minutes.

What is Lambda?

Lambda is an Amazon Web Service that triggers a function in response to a specific event.

Example:

  • Event: Uploading an image to S3 (a.k.a S3 PUT)
  • Function: Generate thumbnail for the uploaded image and place it in a thumbnail folder

Installation

NOTE: This guide assumes that you're already familiar with AWS & S3.

  1. Log in to your AWS account
  2. Click on Lambda from the list of the available services alt text
  3. Click on Get Started
  4. From the left menu choose Configure triggers
  • Choose S3 from the list of available events/services
  • Make sure you choose the appropriate Bucket name
  • Choose Put for event type
  • (optional) Type in a prefix path for images to trigger events for
  • (optional) Choose what type of files to handle (png, jpg, etc..)
  • Enable trigger and click Next alt text
  1. Configuring function
  • Give your function any name you want, add an optional description, and choose Node.js 4.3 as your runtime alt text

  • Upload Thumbnailer.zip as is alt text

  • Create a new role, give it a name, and attach to it S3 object read-only permission policy alt text

  • Hit Next then Create function, and you're good to go!

Once you upload an image to your S3 bucket, an event will be triggered and your image will have a thumbnail autoamtically generated for it in a thumbnail folder.

Customization

All customizations are done to index.js

NOTE: After modifying this file, you MUST compress it with node_modules folder and upload it again to Lambda.

Thumbnail size

Modify THUMB_WIDTH = 300 & THUMB_HEIGHT = 300 with your desired dimensions.

Allowed file types

Modify ALLOWED_FILETYPES

NOTE: Current supported files formats are: 'png', 'jpg', 'jpeg', 'bmp', 'tiff', 'pdf', 'gif'.

Output image format

Modify the following:

  • ContentType: "image/jpg"
  • dstKey = THUMB_KEY_PREFIX + srcKey.replace(/.\w+$/, ".jpg"),
  • .toBuffer("jpg", function(err, buffer) {

NOTE: Currently the thumbnails is in JPG format.

Contributions

Thanks for the amazing engineering team at Saily for their continuous contributions @daniArnaout @musbaalbaki @malekhijazi

Pull requests are warmly welcomed!

License

The MIT License (MIT)

Copyright (c) 2016 Saily

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

aws-s3-lambda-thumbnail-generator's People

Contributors

daniarnaout avatar sailyapp avatar

Watchers

 avatar  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.