Coder Social home page Coder Social logo

aws-lambda-image-compressor's Introduction

aws-lambda-image-compressor

AWS lambda function to compress and resize images

This is a Lambda Function which resizes/reduces images automatically. When an image is put on some AWS S3 bucket, this function will resize/reduce it and save it into a new bucket.

I found 2 projects which doing the same but I could not make them properly work. With the first I could not compress PNG images; with the second I had issues with packaging and module dependency on S3.

I then decided to write my simple function and some gulp task to quickly deploy it into AWS. This article was a great reference.

Flow

The function should be invoked by a S3 trigger when a new image is uploaded to some S3 bucket. Once invoked, the function compresses and resizes (if needed) the original image and save those copies into another bucket. You can easily configure the widths of the resized image and their destination bucket/subfolder.

  • PNG images are saved as JPG
  • if an image is smaller than a desired resizing, it is copied without being resized into destination bucket

Requirements

  • node.js (AWS Lambda working version is 4.3.2)

Usage

  • edit lambda-config.js file and assign name, description, memory size, timeout of your lambda function.
  • edit .env file with your AWS access data
  • npm install
  • gulp deploy

Update Runtime

In case you need to update your runtime environment, you can run the following command:

aws lambda update-function-configuration --function-name <function name as in lambda-config.js> --runtime nodejs4.3

Todo

  • some code optimization
  • tests
  • read images compression/resizing configuration from an external json file

aws-lambda-image-compressor's People

Contributors

dariospadoni avatar pizzapete avatar weijtmans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

aws-lambda-image-compressor's Issues

Stream yields empty buffer error

Hi,

First of all thanks for your script. It is extremely useful.
Unfortunately O get the following error: error during image optimization: Error: Stream yields empty buffer.

Do you have any idea where this comes from?

Kind regards

multiple creation of folders.

With the script, when i put an Image, I have too many files created.

test

test1

Maybe the folder has to be created before the prefix. So The event will not call itself.

Successful messages logged but no images are found in folder

My cloudwatch logs all say the processes were completed and the image was being uploaded to the bucket, but the bucket has nothing in it.

2016-12-01T20:18:46.665Z uploading image EYuB7tLbLF8bFk9aJ/small/testfile.jpg to bucket testbucket-optim

2016-12-01T20:18:48.765Z image uploaded

Any idea where I might look to resolve this?

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.