Lambda function when triggered by an S3 PUT (configured in lambda triggers in AWS) automatically resizes images to "standar sizes" and place them in destination bucket (dsBucket).
Why? Cause S3 + lambda is cheaper than image processor like imgix. Best for small projects that don't really generate revenue.
$ npm install async gm
$ cp config.json.sample config.json
Sample config.json
{
"dstBucket": "dslambdaresize",
"thumbs":[
{"folder":"square", "type":"thumbnail", "geometry":"500x500" },
{"folder":"large" , "type":"resize", "width":"900", "height":"900"},
{"folder":"medium", "type":"resize", "width":"600" },
{"folder":"small" , "type":"resize", "height":"300"}
]
}
dstBucket
: destination bucket (source bucket is determined by trigger in lambda)thumbs
: various size and sharesfolder
: each entry must be unique, or you'll be overwriting the filestype
: processing modethumbnail
: resize and center-crops the imageresize
: simple reduce in size preserving aspect ratio of original
geometry
: required forthumbnail
modeheight
andwidth
: at least one is required forresize
mode
- zip content of the folder
- upload as lambda function
- Lambda Config
- Runtime: Node.js 4.3
- Handler: index.handler
- Memory: 1024MB
- Timeout: 3 min
- Lambda Config
- maker sure dstBucket exists
- Large files (3+ MB) might cause problems. Try allocating more memory in Lambda.
- Start with 1024mb of ram and 2 minutes timeout, and read log to adjust
- Code based on AWS tutorial
- Only handles jpg and png