Code Monkey home page Code Monkey logo

lambda-convert's Introduction

lambda-convert

AWS Lambda powered drop-in replacement for ImageMagick convert command line tool

Background

At Envoy, we have many image file uploaded by users and will be resized via convert (ImageMagick) command line tool. It works fine, the only problems are

Dealing with big GIF image

When user upload a GIF image, to resize it, ImageMagick will need to load the all frames into memory. In that case, even the GIF image file is very small, could posiblly consume huge amount of memory. This brings big impact to our API server, and sometimes the uploading request fails due to this reason.

Security concerns

Despite it's not really easy to perform, it still possible to leverage exploits of certain image file format loading code in ImageMagick.

Solution

To eliminate the big image file uploading issue and the security risk, the idea here is to do image resizing on AWS Lambda instead of localhost. This command line tool is a drop-in replacement for convert command, except it upload the input image file to S3, does the resizing on AWS Lambda and finally down the result image back to localhost.

Environment variables

  • CONVERT_S3_REGION - AWS region for S3, default value will be read from AWS_REGION if this environment variable is not set.
  • CONVERT_LAMBDA_REGION - AWS region for Lambda, default value will be read from AWS_REGION if this environment variable is not set.
  • CONVERT_ACCESS_KEY - AWS access key, default value will follow standard aws-sdk credential lookup sequence
  • CONVERT_SECRET_ACCESS_KEY - AWS secret key, default value will follow standard aws-sdk credential lookup sequence
  • CONVERT_S3_BUCKET - AWS S3 bucket. (required)
  • CONVERT_S3_KEY_PREFIX - AWS S3 temporary file uploading prefix, default value is _convert_tmp/
  • CONVERT_LAMBDA_FUNCTION - Name of the AWS Lambda function to invoke, default value is image-convert-prod
  • CONVERT_DISABLE_FALLBACK - By default, this command line tool fallbacks to local convert command if remote operation fails. Set this value to 1 to disable the fallback behavior.

The AWS Lambda function

The AWS Lambda function for running ImageMagick can be found here at https://github.com/envoy/envoy-convert

lambda-convert's People

Contributors

fangpenlin avatar diegoeche avatar reedloden avatar

Watchers

 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.