Giter Club home page Giter Club logo

serverless-docker-image-resize's Introduction

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!

serverless-docker-image-resize's People

Contributors

adnanrahic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

serverless-docker-image-resize's Issues

Which license is this code released under

I'm borrowing some technical ideas from the article you have published, as I'm working on implementing a very similar on-the-fly image scaling capability in this project:

littermap/littermap-aws-backend#2

I'm specifically looking for a solution where the image stream is continuously processed and the resulting stream pushed to its destination right as it's downloading the source image data.

This repository doesn't appear to mention an open source license, so I'd like to inquire which license you're sharing this code under.

typo

volumes options have ":" in the path

docker-compose.yml
version: '3' services: image-resize-on-the-fly: build: . volumes: - ./secrets:/deploy/secrets env_file: - ./secrets/secrets.env

Image is not resizing.

I've cloned your repo to my local system.

then update a details SSL_KEY, SLS_SECRET, STAGE, REGION, BUCKET in secrets.env file.

I want to use node version 10 so I change it to bucket/serverless.yml and functions/serverless.yml and Dockerfile.

At last, I run command docker-compose up --build

I kept en eye on the output of a docker-compose command and everything is set up nicely.

it has created 2 S3 bucket image-resize-on-the-fly-serverlessdeploymentbuck-15sulaxg0lhop, image-resize-on-the-fly-serverlessdeploymentbuck-2lofzjreudgm and one bucket that I updated in secrets.env file to store images. two cloudformation stacks image-resize-on-the-fly-bucket-dev and image-resize-on-the-fly-functions-dev and one lambda function.

then I upload an image to S3 bucket. : S3_BUCKET_URL/image.jpg and I can access this URL.

Then I tried S3_BUCKET_URL/500x500/image.jpg but it's given me an error and I've attached error screen. it's not creating resize image.

Any help would be grateful.

error (1)

HTTPS image access

Feature Request: Allow an user to access images via HTTPS

Example:
http://$BUCKET.s3-website.$REGION.amazonaws.com/700x700/ab.jpeg
to
https://$BUCKET.s3-website.$REGION.amazonaws.com/700x700/ab.jpeg

Any chance?

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.