AWS Lambda + Node Modules, no Docker required

Compressing images on the fly using AWS Lambda and Node

Some context

My image compression pipeline

Consisting of the client, two S3 buckets and a Lambda function, the images don’t need to even touch my server

Using node modules in Lambda

Some modules are pickier than others

Error: spawn /var/task/node_modules/mozjpeg/vendor/cjpeg ENOENT

Where Docker comes in (or doesn’t in this case)

>> docker pull amazonlinux
>> docker run -v $(pwd):/my-lambda-fn -it amazonlinux

Using CodeBuild to install dependencies

version: 0.2phases:
install:
commands:
- npm install
artifacts:
files:
- '**/*'
my-lambda-function.zip
---| index.js
---| package.json
---| buildspec.yml

Hooking up to Lambda

Image Compression

Software Engineer — haydnjm.com