GithubHelp home page GithubHelp logo

einselbst / image-resize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from infographicsgroup/image-resize

0.0 0.0 0.0 608 KB

Typescript implementation for AWS Lambda (sharp) image resizing

TypeScript 83.74% JavaScript 10.71% Dockerfile 5.54%

image-resize's Introduction

Image-Resize

Serverless Framework-based AWS Lambda function triggered by S3 events to resize images with the excellent Sharp module. By using the Sharp module (which uses the libvips library), image processing can be 3x-5x faster than using ImageMagick, thus reducing the time your function spends running, which can potentially dramatically decrease your lambda function's cost. The function's behaviour can be controlled entirely with configuration.

Contents

  1. What is it?
  2. Installation
  3. Setup
  4. Testing
  5. Local Invocation
  6. Deployment
  7. Rollback
  8. Logs

What is it?

A tool to take images uploaded to an S3 bucket and produce one or more images of varying sizes, optimizations and other operations. It does this by creating an AWS Lambda function with the help of the Serverless Framework.

It listens to the files created in the sourceBucket in the ./config.json and output the original format + additionalFormats (defined in the configuration) and upload the generated images to the destinationBucket.

Installation

Prerequisites

You should know your AWS credentials and the following software needs to be available on your system, install info for MacOS is given:

Source Code

Clone the github repo, e.g. by using the following commands:

git clone https://github.com/infographicsgroup/image-resize
cd image-resize
yarn install

Or, if you have serverless installed globally:

serverless install -u https://github.com/infographicsgroup/image-resize

Setup

Credentials

You must configure your AWS credentials by defining AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environmental variables.

export AWS_ACCESS_KEY_ID=<your-key-here>
export AWS_SECRET_ACCESS_KEY=<your-secret-key-here>

Buckets

The buckets must exist. They need to be set in the config.json file. When the project is deployed, the S3 trigger needs to be manually set in the AWS Lambda console: Configuration -> Add triggers -> S3 -> Choose correct source bucket -> Add -> Save.

Testing

TBD

Local Invocation

To simulate API Gateway locally using serverless-offline

$ serverless offline start

It starts a local s3 server on http://localhost:4569 In another terminal window/tab, you can trigger the function by uploading a (fake) file offline using aws CLI command

$ aws --endpoint http://localhost:4569 s3api put-object --bucket staging-uploads-visualpedia.igg.cloud --key test.png --body ./test.png

Deployment

By default if no --stage option passed, stage defaults to dev (local/staging) environment for production use --stage production

# Staging
$ yarn deploy
$ docker-compose run deploy

# Production
$ yarn deploy-production
$ docker-compose run deploy-production

Rollback

TBD

Logs

# Staging
$ yarn logs
$ serverless logs -f resizeImage -t
$ serverless logs -f resizeImage -t --stage dev

# Production
$ yarn logs --stage production
$ serverless logs -f resizeImage -t --stage production

image-resize's People

Contributors

a14m avatar dependabot[bot] avatar tn1ck 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.