Coder Social home page Coder Social logo

aws-lambda-image-compressor-java's Introduction

AWS-Lambda-Image-Compressor-Java

Lambda Function that compresses PNG and JPG files. Replaces original file in S3 with compressed. Reduces image size while keeping quality loss at minimal. Outputs new file in the original image location of S3.

Instructions:

  1. Install Maven.
brew install maven
  1. Clone this repo.

  2. cd into this repo.

  3. Package as shaded JAR

mvn clean package shade:shade
  1. A target folder with the final JAR artifact will be created. In this case the name of the the JAR artifact will be 'image-compression-1.0-SNAPSHOT.jar'

  2. Create a new Lambda Function on AWS. Make sure to add a role with all the appropiate permissions (S3 read and write, CloudWatch, etc).

  3. Upload shaded JAR.

  4. Set up a S3 trigger for Object creation in your desired bucket-> Object Created (all).

  5. Change Handler Field to:

Index::handleRequest
  1. Increase Memory and Timeout Limit (otherwise function will timeout)

  2. Done. Now whenever a PNG or JPG is uploaded to the bucket with the S3 event added on step 8, this function will get fired and the image will get compressed.

Optional: If you wish to change the compression rate, you can change the value in line 96 of index.java

HappyFace.jpg

Before

Before

After

After

aws-lambda-image-compressor-java's People

Contributors

whoisjuan avatar

Stargazers

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