• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple serverless image resize on-the-fly - Deploy with one command - Built with AWS Lambda and S3

Image resize on the fly AWS Lambda function with Serverless and Node.js

A simple Serverless service for creating an image resize-on-the-fly function with AWS Lambda. For Sharp to work correctly it must be installed in the same environment the production is running in. Because AWS Lambda is running on Amazon Linux it must be installed on the same system.

For this purpose we're using Docker to spin up a container, install the Serverless Framework and deploy the function from inside the container.

This service will deploy both the AWS Lambda function and AWS S3 bucket from where the images will be grabbed, resized and put back.

Getting Started (Ubuntu-based Linux Systems)

These instructions will get you up and running. See deployment for notes on how to deploy the project on a live system.

Clone to your local machine:

$ git clone https://github.com/adnanrahic/serverless-docker-image-resize.git

Change into the cloned dir:

$ cd serverless-docker-image-resize

Install Docker and docker compose:

  1. Install Docker
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update
$ apt-cache policy docker-ce
$ sudo apt-get install -y docker-ce

After typing the command:

$ sudo systemctl status docker

You should see the service is running.

Output
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago
     Docs: https://docs.docker.com
 Main PID: 749 (docker)
  1. Install Docker Compose
$ sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose -v

This will print the installed version:

Output
docker-compose version 1.21.2, build a133471

All dependencies are installed. Now, deployment is a breeze.

Deployment

Configure secrets

1. secrets.json

The deploy.sh script will autogenerate this file. No need to touch it at all.

2. secrets.env

Add your secret keys and configuration variables here.

SLS_KEY=XXX
SLS_SECRET=YYY
STAGE=dev
REGION=us-east-1
BUCKET=images.your-domain.com

Run Docker Compose

$ docker-compose up --build

This will build the image, create a container, run the deploy.sh script inside the container and deploy all the resources.

The command line will log out the service endpoints and all info. What's important to note is the bucket name and URL you need to access your images. Check out Usage.

Usage

After the service has been deployed, you will receive a bucket endpoint. You will add a query parameter to it in order to tell it how to resize the image. The bucket will behave as a public website.

Let's upload an image so we have something to work with.

$ aws s3 cp --acl public-read IMAGE_NAME.jpg s3://BUCKET

Example 1:

http://BUCKET.s3-website.REGION.amazonaws.com/420x360/IMAGE_NAME.jpg

Or you can access the lambda function directly.

Example 2:

https://LAMBDA_ID.execute-api.REGION.amazonaws.com/dev/resize?key=420x360/IMAGE_NAME.jpg

This will resize the image in the fly and send you back the resized image while storing it for further reference.

Credits

The original tutorial for resizing S3 images I followed can be found here!

More Repositories

1

securing-restful-apis-with-jwt

How to secure a Nodejs RESTful CRUD API using JSON web tokens?
JavaScript
336
star
2

nodejs-restful-api

How to create a RESTful CRUD API using Nodejs?
JavaScript
327
star
3

a-crash-course-on-serverless-auth

A short and easy boilerplate showcasing JWT auth with Nodejs, the Serverless framework, MongoDB and AWS Lambda.
JavaScript
159
star
4

serverless-side-rendering-react-next

Sample repo for setting up Next and React on AWS Lambda with the Serverless Framework.
JavaScript
121
star
5

serverless-side-rendering-vue-nuxt

Sample project for using Nuxt.js to create a server-side rendered Vue.js app on AWS Lambda and AWS API Gateway.
JavaScript
118
star
6

lambda-mailer

Simple module for receiving an email from a contact form on your website.
JavaScript
83
star
7

building-a-serverless-api-with-nodejs-and-aws-aurora-serverless

JavaScript
62
star
8

building-a-serverless-rest-api-with-nodejs

A quick and easy guide of how to hook up a single Serverless service with basic MongoDB connection and CRUD interaction.
JavaScript
62
star
9

gulp-all-the-things

This tutorial will demo how to set up a bare bones Gulp configuration for automating the time consuming tasks you need to run on a regular basis.
JavaScript
32
star
10

lambda-sns-dlq-error-handling

Sample project for showing the ability to publish an SNS topic and trigger a function from the topic. Code is structured to create a timeout/crash so the dead letter queue SNS topic gets published, in turn triggering the error handler function.
JavaScript
31
star
11

a-crash-course-on-serverless-with-nodejs

A quick and easy guide of how to hook up a single Serverless service.
JavaScript
28
star
12

boilerplate-api

Lightweight Node.js boilerplate API with Docker support, test coverage and circle.ci support.
JavaScript
24
star
13

a-crash-course-on-serverless-apis-with-express-and-mongodb

JavaScript
20
star
14

express-sls-app

How to deploy a Node.js application to AWS Lambda using Serverless, a quick start.
JavaScript
19
star
15

express-docker-app

Hyperminimal setup of an Express app with Docker. :)
Dockerfile
15
star
16

building-a-serverless-rest-api-with-nodejs-and-mongodb-stitch

Sample repository for building a serverless service on AWS Lambda with MongoDB Stitch as a persistent data store
JavaScript
10
star
17

load-balancing-nodejs-in-production

Four samples of how to load-balance Node.js in production.
JavaScript
9
star
18

a-crash-course-on-testing-with-nodejs

JavaScript
9
star
19

meetup-lucky-winner-generator

A simple package with zero dependencies for generating lucky winners if there is a free coupon giveaway at a Meetup event!
JavaScript
6
star
20

hacktoberfest-sarajevo

Official resources for the Sarajevo Hacktoberfest Open Hack Day
5
star
21

express-sls-app-with-stitch

Sample repository for building a serverless service on AWS Lambda with MongoDB Stitch as a persistent data store
JavaScript
5
star
22

nodejs-monitoring-sematext

Starter setup for monitoring Node.js apps with Sematext
JavaScript
5
star
23

javascriptzapocetnike

Exersize Files
HTML
5
star
24

adnanrahic.com

HTML
4
star
25

sls-node11

JavaScript
3
star
26

Serverless-JavaScript-By-Example

JavaScript
3
star
27

a-gentle-intro-to-express

JavaScript
3
star
28

getting-started-with-aws-lambda-and-nodejs

JavaScript
2
star
29

a-crash-course-on-docker

HTML
2
star
30

nodejs-logging-made-easy

JavaScript
1
star
31

weather-app

JavaScript
1
star
32

cdn

1
star
33

a-crash-course-on-integration-testing-with-nodejs

JavaScript
1
star
34

bita4students-nodejs-api

JavaScript
1
star
35

FinalNotesApp

JavaScript
1
star
36

mean-stack-101

MEAN Stack Boilerplate - Intro to the MEAN stack with a notes app
JavaScript
1
star
37

kubernetes-sandbox

Shell
1
star
38

tracetest-docs-update

JavaScript
1
star
39

node-memory-leaks

JavaScript
1
star
40

vanilla-js-app

Creating an app using ES5
JavaScript
1
star
41

error-handling-made-easy

JavaScript
1
star
42

boilerplate-api-ts

This will soon be a lightweight Node.js boilerplate API with TypeScript, Docker support, test coverage and circle.ci support.
TypeScript
1
star