All Projects → nicholasgubbins → Serverless Image Resizer

nicholasgubbins / Serverless Image Resizer

Licence: mit
Serverless image resizer like imgix on API Gateway & Lambda

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Serverless Image Resizer

Aws Lambda Dotnet
Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
Stars: ✭ 945 (+1717.31%)
Mutual labels:  serverless, aws-lambda
Lambda Packs
Precompiled packages for AWS Lambda
Stars: ✭ 997 (+1817.31%)
Mutual labels:  serverless, aws-lambda
Graphql Serverless
Sample project to guide the use of GraphQL and Serverless Architecture.
Stars: ✭ 28 (-46.15%)
Mutual labels:  serverless, aws-lambda
Serverless Es Logs
A Serverless plugin to transport logs to ElasticSearch
Stars: ✭ 51 (-1.92%)
Mutual labels:  serverless, aws-lambda
Serverless Export Env
Serverless plugin to export environment variables into a .env file
Stars: ✭ 51 (-1.92%)
Mutual labels:  serverless, aws-lambda
Aws Auto Terminate Idle Emr
AWS Auto Terminate Idle AWS EMR Clusters Framework is an AWS based solution using AWS CloudWatch and AWS Lambda using a Python script that is using Boto3 to terminate AWS EMR clusters that have been idle for a specified period of time.
Stars: ✭ 21 (-59.62%)
Mutual labels:  serverless, aws-lambda
Lamlight
Lamlight is a command line tool to allow easy handling of AWS lambda functions. It allows to put heavy dependencies like numpy and scipy on AWS lambda and updating your lambda function very quickly.
Stars: ✭ 37 (-28.85%)
Mutual labels:  serverless, aws-lambda
Lamb
monitoring tool for better visibility when developing AWS Lambda functions
Stars: ✭ 11 (-78.85%)
Mutual labels:  serverless, aws-lambda
Corgi
AWS Lambda / API Gateway native, fast and simple web framework
Stars: ✭ 44 (-15.38%)
Mutual labels:  serverless, aws-lambda
Chalice
Python Serverless Microframework for AWS
Stars: ✭ 8,513 (+16271.15%)
Mutual labels:  serverless, aws-lambda
Cobolambda
Serverless COBOL on AWS Lambda.
Stars: ✭ 48 (-7.69%)
Mutual labels:  serverless, aws-lambda
Aws Power Tuner Ui
AWS Lambda Power Tuner UI is an open source project creating a deployable easy to use website built on a layered technology stack allowing you to optimize your Lambda functions for cost and/or performance in a data-driven way via an easy to use UI.
Stars: ✭ 52 (+0%)
Mutual labels:  serverless, aws-lambda
Step Functions Demo
This is a demo project, created as a part of the blog post. The project uses serverless for deployments.
Stars: ✭ 15 (-71.15%)
Mutual labels:  serverless, aws-lambda
Unicorn Mart
A proof of concept e-commerce store leveraging Contentful, GatsbyJS, Stripe, and serverless via clay.run
Stars: ✭ 21 (-59.62%)
Mutual labels:  serverless, aws-lambda
Cloudmagick
CloudMagick is a serverless application which provides a dynamic image transformation like the small light module of apache2
Stars: ✭ 11 (-78.85%)
Mutual labels:  serverless, aws-lambda
Serverless Plugin Stackstorm
Plugin for serverless framework to run ready to use actions from StackStorm Exchange as AWS Lambda.
Stars: ✭ 28 (-46.15%)
Mutual labels:  serverless, aws-lambda
Serverless Plugin Select
Select which functions are to be deployed based on region and stage.
Stars: ✭ 25 (-51.92%)
Mutual labels:  serverless, aws-lambda
Serverless Python Requirements
⚡️🐍📦 Serverless plugin to bundle Python packages
Stars: ✭ 838 (+1511.54%)
Mutual labels:  serverless, aws-lambda
Serverless Next
How to use Serverless to provide the frontend with a full API with minimal effort and max. scalability
Stars: ✭ 41 (-21.15%)
Mutual labels:  serverless, aws-lambda
Aws Serverless Java Container
A Java wrapper to run Spring, Jersey, Spark, and other apps inside AWS Lambda.
Stars: ✭ 1,054 (+1926.92%)
Mutual labels:  serverless, aws-lambda

Serverless-Image-Resizer

Build Status dependencies Status devDependencies Status NPM version Twitter URL

Serverless-Image-Resizer is an image processing service that runs on AWS Lambda and S3.

Summary

Put simply, Serverless-Image-Resizer works by requesting an image file from S3 and applying image processing functions to that image. Image processing functions are sent as query parameters in the request URL. Serverless-Image-Resizer first checks to see if the requested image (including effects) is stored in S3. If it is, then the cached version is returned. If it is not, then the processing functions are applied to the original image, and the resulting image is cached in S3 and sent back to the requester.

Example

The original image on the left has been vertically resized to 300 px and has had a blur of radius 0 and sigma 3 applied to create the image on the right. The URL to perform this effect would be https://API-URL.com/path/to/image.jpg?h=300&b=0x3.

Original Edited

Setup

AWS and Serverless

This project relies on AWS + The Serverless Framework to deploy and manage your service. If it is not already, install serverless globally:

$ npm install -g serverless

You will need an AWS account to deploy this service. If you do not already have one, sign up at https://aws.amazon.com

You will need AWS credentials to programmatically deploy your service from the commandline. Follow the Serverless AWS Credentials documentation to get setup.

Code

There are two ways to get the project code, choose from one of the options:

  1. Clone the project and deploy from that project directory
  2. npm install the module and incorporate it into your own project

Clone

$ git clone https://github.com/nicholasgubbins/Serverless-Image-Resizer.git && cd Serverless-Image-Resizer
$ git checkout $(git describe --tags `git rev-list --tags --max-count=1`) # checkout latest release
$ npm i # or $ yarn

npm

In your project directory, npm install the node module and the browserify serverless plugin:

$ npm install --save serverless-image-resizer
$ npm install --save-dev serverless-plugin-browserify

You can change where the function handlers live by editing functions.FUNCTION_NAME.handler in serverless.yml, but using the paths that are there now, you would use serverless-image-resizer by creating the files below:

// in functions/resizeImage/index.js
const { resizeImage } = require('serverless-image-resizer');

module.exports.handler = resizeImage.handler;


// in functions/getImage/index.js
const { getImage } = require('serverless-image-resizer');

module.exports.handler = getImage.handler;

You will also need to copy serverless.yml to the top level of your project directory.

Rename the AWS Region and S3 bucket

In serverless.yml change provider.region to the AWS Region your S3 bucket exists in, and where you want your Lambda Function and API Gateway endpoints to exist. Also change provider.environment.BUCKET to be the name of your S3 bucket.

Deploy the service

Using serverless, deploy the service from the top level of the project:

$ sls deploy

API Gateway Binary Support

Currently, there is no way to configure Binary Support using serverless (related serverless issue). For now we can set this manually using the AWS Console:

  1. Open the AWS Console
  2. Click the API Gateway Service
  3. Click on your service in the left sidebar
  4. Click "Binary Support"
  5. Click the "Edit" button on the right side of the page
  6. Add */* to the text input and click "Save"
  7. Click on your service in the left sidebar
  8. The "Actions" dropdown button should have an orange dot next to it, click on the "Actions" button.
  9. Click on "Deploy API" in the dropdown menu
  10. Select the "dev" service (or another service if you have configured one)
  11. Click the "Deploy" button

You're done!

Once you've reach this point your service is ready to use.

You can run $ sls info to print out the details about your service. You should see one "endpoint" that has a GET method. Copy this URL and paste it into your browser. Replace {proxy+} with a path to one of your images in S3 (omitting the BUCKET_NAME defined in serverless.yml). For example:

https://LAMBDA-ID.execute-api.eu-west-1.amazonaws.com/dev/path/to/image.png

Usage

Serverless-Image-Resizer supports the following query params:

Parameter Description Format Example
w width number ?w=150
h height number ?h=200
w&h crop number ?w=150&h=200
f filter string ?q=Point
q quality number ?q=2
m max number ?m=3
b blur numberxnumber ?b=0x7

For example:

https://LAMBDA-ID.execute-api.eu-west-1.amazonaws.com/dev/path/to/image.png?w=100&h=200&b=0x3

Development

AWS Lambda supports node 6.10.2 so that should be used during development. If you have nvm installed you can run $ nvm use to use the version in the .nvmrc file.

Linting

This project uses the eslint-config-airbnb linting configuration. To run eslint execute the lint command:

$ npm run lint

Testing

Tests are written and executed using Jest. To write a test, create a FILE_NAME.spec.js file and Jest will automatically run it when you execute the test command:

$ npm test
$ npm run test:watch     # to test as you develop
$ npm run test:coverage  # to test code coverage

Note that npm run test:coverage will create a coverage folder that is gitignored.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].