All Projects → apoca → lambda-resize-image

apoca / lambda-resize-image

Licence: MIT license
An AWS Lambda Function to resize images automatically with API Gateway and S3 for imagemagick tasks. When an image is called on AWS Api Gateway, this package will resize it and send it to the S3.

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to lambda-resize-image

aws-maven-plugin
Deploys resources to AWS using maven
Stars: ✭ 25 (-55.36%)
Mutual labels:  lambda, aws-s3
Node S3 Uploader
Flexible and efficient resize, rename, and upload images to Amazon S3 disk storage. Uses the official AWS Node SDK for transfer, and ImageMagick for image processing. Support for multiple image versions targets.
Stars: ✭ 237 (+323.21%)
Mutual labels:  imagemagick, aws-s3
wrender
Image compression and transformation reverse-proxy for Express apps
Stars: ✭ 14 (-75%)
Mutual labels:  cdn, sharp
multer-sharp-s3
Multer Sharp S3 is streaming multer storage engine permit to transform / resize the image and upload to AWS S3.
Stars: ✭ 54 (-3.57%)
Mutual labels:  aws-s3, sharp
Image Resizer
On-the-fly image resizing using Node.js and libvips. Heroku Ready!
Stars: ✭ 59 (+5.36%)
Mutual labels:  cdn, aws-s3
ipx
High performance, secure and easy to use image proxy based on Sharp and libvips.
Stars: ✭ 683 (+1119.64%)
Mutual labels:  cdn, sharp
lambda-memory-performance-benchmark
Performance and cost benchmark tool for AWS Lambda on memory sizes 📈⏱
Stars: ✭ 60 (+7.14%)
Mutual labels:  lambda
Bucket-Flaws
Bucket Flaws ( S3 Bucket Mass Scanner ): A Simple Lightweight Script to Check for Common S3 Bucket Misconfigurations
Stars: ✭ 43 (-23.21%)
Mutual labels:  aws-s3
flask-drive
A simple Flask app to upload and download files off Amazon's S3
Stars: ✭ 23 (-58.93%)
Mutual labels:  aws-s3
aws-backup-lambda
A utility AWS lambda function to manage EBS and RDS snapshot backups.
Stars: ✭ 60 (+7.14%)
Mutual labels:  lambda
aws-s3-backup
This app allows you to use AWS (Amazon Web Services) S3 as backup system for desktop environments. 🚀
Stars: ✭ 67 (+19.64%)
Mutual labels:  aws-s3
slic-watch
Easy alarms and dashboards for Lambda, DynamoDB, API Gateway, Kinesis, Step Functions and more
Stars: ✭ 88 (+57.14%)
Mutual labels:  lambda
cora
Genius programmer should write his own lisp!
Stars: ✭ 40 (-28.57%)
Mutual labels:  lambda
ooso
Java library for running Serverless MapReduce jobs
Stars: ✭ 25 (-55.36%)
Mutual labels:  lambda
FuzzImageMagick
Sample files for fuzzing ImageMagick
Stars: ✭ 15 (-73.21%)
Mutual labels:  imagemagick
lambda-ci
CI/CD for Lambda Functions with Jenkins
Stars: ✭ 20 (-64.29%)
Mutual labels:  lambda
cyan
Cyan Color Converter
Stars: ✭ 68 (+21.43%)
Mutual labels:  imagemagick
terraform-aws-s3-object
Terraform module which creates S3 object resources on AWS
Stars: ✭ 15 (-73.21%)
Mutual labels:  aws-s3
laravel-assetcachebuster
Laravel 5 package that prefixes asset urls with a unique hash which will allow invalidation of asset files cached by the browser.
Stars: ✭ 33 (-41.07%)
Mutual labels:  cdn
MagickSlicer
Map tiles generator
Stars: ✭ 73 (+30.36%)
Mutual labels:  imagemagick

lambda-resize-image

Build Status Codacy Badge Maintainability npm version dependencies Status devDependencies Status npm

An AWS Lambda Function to resize images automatically with API Gateway and S3 for imagemagick tasks. When an image is called on AWS Api Gateway, this package will resize it and send it to the S3.

Contents

Requirements

  • Node.js - AWS Lambda supports versions of 10.20.1 or above (Recommended: 12.X).

New version 2.0

We've changed our approache to remove redirects from our responses. Then, we are returning a binary file base 64 image file.

Steps to version 2.0

You must have AWS CLI installed to execute a command from your console:

aws apigateway update-integration-response --rest-api-id <API_ID> --resource-id <RESOURCE_ID> --http-method GET --status-code 200 --patch-operations '[{"op" : "replace", "path" : "/contentHandling", "value" : "CONVERT_TO_BINARY"}]'

In API GW -> Settings -> Binary Media Types and add:

*/*

What is it?

It's AWS Lambda, which is a compute service that lets you run code without provisioning or managing servers.

Read more about AWS Lambda.

Description

The combination of API Gateway and Lambda is very powerful. It allows you to build some complex functionalities without maintaining any virtual machines yourself. Lambda can be hooked up to many other (AWS) Services including S3. That's why I decided to build an AWS Lambda Function to resize images automatically with API Gateway and S3 for imagemagick tasks. When an image is called on AWS S3 bucket (via API Gateway), this package will resize it and send it to the S3 before redirecting you to the new path of the image (aws bucket url or CDN).

Features

Instalation

First, add Serverless globally:

npm install -g serverless

Then, clone the repository into your local environment:

git clone https://github.com/apoca/lambda-resize-image
cd lambda-resize-image
npm install

Modify and set the .env.example to env.yml with your data. (You are supposed to have already configured your local variables).

AWS credentials

To run local development you also might need to configure you aws credentials, or you can set them to what I've shown below.

Deploy to Amazon AWS

You can also check if you have everything installed in the correct way:

$ serverless

To deploy from your environment to Amazon AWS, you must:

$ serverless deploy --stage dev or $ serverless deploy --stage prod for production configurations.

Then, serverless will package, validate and upload your stack to Amazon AWS. It will probably look like this:

Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (1.52 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...
Service Information
service: resizeS3Image
stage: development
region: eu-west-1
stack: resizeS3Image-development
api keys:
  None
endpoints:
  GET - https://<api_key_here>.execute-api.eu-west-1.amazonaws.com/dev/{key+}
functions:
  handler: resize-dev-image
Serverless: Removing old service artifacts from S3...

When upload to AWS Lambda, the project will bundle only needed files - no dev dependencies will be included.

Usage (image restrictions resize)

To restrict the dimensions, we put a const var in the handle.js:

const ALLOWED_DIMENSIONS = {
  width: 1800,
  height: 1800
};

You can also change the url endpoint https://<api_key_here>.execute-api.eu-west-1.amazonaws.com/dev/{key+} to another one more tiny and cachable (cloudfront), you can also configure in you Api Gateway (lambda service) a Custom Domain Name.

Example URL usage

https://<api_key_here>.execute-api.eu-west-1.amazonaws.com/dev/<KEY_S3_IMAGE_HERE>?width=<WIDTH>&height=<HEIGHT>

or with you own Custom Domain Names:

https://api.yourdomain.com/<KEY_S3_IMAGE_HERE>?width=<WIDTH>&height=<HEIGHT>

Example usage of lambda resize image

Environment variables

  • URL - AWS URL S3 bucket or your CDN url to the BUCKET. (not required in version 2.0)
  • BUCKET - AWS S3 bucket. (required)

Environment variables for serverless

  • AWS_ACCESS_KEY_ID - AWS key
  • AWS_SECRET_ACCESS_KEY - AWS Secret

Local development

  1. $ npm i -g serverless
  2. $ npm i
  3. $ brew install imagemagick
  4. $ serverless offline start

Note that you will need to be into the root repository. The last command (4.) will spin up an serverless-offline version of an API Gateway, that will simulate the real one. Once it is running, you can see all the requests on your command line.

Example request

http://localhost:3000<YOUR_KEYNAME_TO_IMAGE>?width=<WIDTH>&height=<HEIGHT>

Configuration Parameters

Parameter type description
width Integer Required. Will resize image via imagemagic resize.
height Integer Optional. Will resize image via imagemagic crop.

Feedback

We'd love to get feedback on how you're using lambda-resize-image and things we could add to make this tool better. Feel free to contact us at [email protected]

Contributing

If you'd like to contribute to the project, feel free to submit a PR. See more: CODE_OF_CONDUCT.md

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Author

  • Miguel Vieira - Initial work - apoca

See also the list of contributors who participated in this project.

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].