A simple out of the box serverless media worker
Table of Content
A ready-to-use configurable media worker for image compression and video transcoding tasks. You can compress images and transcode videos at ease. This is higly scalable because of the serverless architecture it supports.
As simple as running a 2-3 commands, one time setup and nothing more. We promise!
⚡Currently supports only AWS Lamba
This package internally uses Serverless Framework for maintainance and deployment purposes.
# 1. Install Serverless CLI tool > npm install -g serverless # 2. Install NPM dependencies > npm install
Before deployment you need to configure the
aws-cli user first. This worker will automatically detect your
By default, the
media-workerwill be triggered when you PUT images inside the
originals/directory in the mentioned AWS S3 bucket.
#1: Configure aws-cli
To know how to configure, a good explaination is given here.
Make sure all necessary permissions are given to the aws-cli user, otherwise you won’t be able to deploy the worker
#2: Environment Variables Setup
We have added an
.env.example file to know what all variables are needed for configuration.
# 1. Copy the .env.example to following > cp .env.example .env.production # for production environment > cp .env.example .env.development # for development environment
For better debugging and development purpose, this package enforces
Variables needed are:
|APP_SERVICE||Name of the main service, for example:
|APP_STAGE||Stage of the worker,
|LAMBDA_NAME||Name of the Lambda function|
|APP_AWS_REGION||AWS region of the app, where all of the resources will be deployed|
|APP_S3_BUCKET||AWS S3 Bucket Name, see the rules here.|
|APP_REPORTING_SERVER_URL||Absolute webhook URL, where the meta data of the image will be posted once it is sucesfully compressed, method used will be
|APP_REPORTING_SERVER_HEADERS||In some case you may need to send custom headers, if so provide them in `”KEY1|
#3: Image Variants Configuration
We provide some pre-defined variants for image processing. However, if you wish to generate your custom variants you can do so very easily.
- Go to config/image.js
- Add your variant in the
variants array expects an object as it’s child, which can have below mentioned possible key-value pairs
|Key||Possible Values||Description||Default Value|
|width||0-10000||max width of the image after compression. Note: Image’s width can be <=
|height||0-10000||max height of the image after compression. Note: Image’s height can be <=
||The path inside the S3 bucket where the variant of the image is to be put||—|
||Format to which the variant to be compressed to, independent of the input image’s format||input image’s format|
||To blur the images or not. Helpful when generating mini thumbnails of the images||
|quality||0-100||Quality of the compressed image variant in respect to the input image’s quality||90|
||To preserve the aspect-ratio of the image variant or not||
We strongly recommend to follow this step before jumping to deployment step.
We provide a simple command to invoke the function to test the invocation of the
To test, simply run:
> npm run invoke -- --path mocks/image.json
We have already added mock events for
aws-cli is configured you can simply pass the name of the file to compress and see the magic
Once you are done with all your testing and ready for deployment, follow the below mentioned steps.
We support two environments,
dev out of the box. In most of the cases these two environments will be sufficient for all purpose.
# For Staging Environment > npm run deploy:dev # For Production Environment > npm run deploy:prod
To know what is happening, run the command in verbose mode:
# For Staging Environment > npm run deploy:dev -- --verbose # For Production Environment > npm run deploy:prod -- --verbose
For more support and options, see the link here.
- AWS Cloudformation Template – Deploy directly from AWS Console
- Terraform Support
- and much more…
We are a bunch of dreamers, designers, and futurists. We are high on collaboration, low on ego, and take our happy hours seriously. We’d love to hear more about your product. Let’s talk and turn your great ideas into something even greater! We have something in store for everyone.
The MIT License. Please see License File for more information. Copyright © 2020 SquareBoat.