Has anyone successfully built a package for AWS lambda distribution?
The following closed issue discuss that subject, however the resulting package size issue has not beed addressed:
https://github.com/justadudewhohacks/opencv4nodejs/issues/113
I've followed the recipe for building native module here:
https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/
But the resulting node_modules ends up being over 1gb, leading to this error from Lambda:
"Unzipped size must be smaller than 262144000 bytes"
Here's how I finally succeeded setting up as a layer with Serverless Framework. Final package size is 46.7Mb
https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/
cd layer/nodejs/
PKG_CONFIG_PATH=~/opencv/lib/pkgconfig/ npm install opencv4nodejs
npm i --savedev serverless-plugin-zip-symlinks-compress-harder
rm -r layer/nodejs/node_modules/opencv-build/opencv/build/share
rm -r layer/nodejs/node_modules/opencv-build/opencv/build/modules
rm -r layer/nodejs/node_modules/opencv-build/opencv/build/3rdparty
rm -r layer/nodejs/node_modules/opencv-build/opencv/build/CMakeFiles
rm -r layer/nodejs/node_modules/opencv-build/opencv/build/downloads
rm -r layer/nodejs/node_modules/opencv-build/opencv/build/include
rm -r layer/nodejs/node_modules/opencv-build/opencv/build/lib64
mv nodejs/node_modules/opencv-build/opencv/build/lib/* nodejs/node_modules/opencv4nodejs/build/Release/
service: lambda-layer-opencv
provider:
name: aws
plugins:
layers:
opencv:
path: nodejs
description: nodejs package of Opencv library and dependencies
package:
artifact: lambda-layer-opencv.zip
resources:
Outputs:
OpencvLayerExport:
Value:
Ref: OpencvLambdaLayer
Export:
Name: OpencvLambdaLayer
After a frustrating couple of days here is the layer I came up with for lambdas running 10.15: https://dropfile.nl/get/hK96J
It's quite large (unzips to 159mb...) but thankfully still remained within the limits for my lambda. Might be possible to reduce the size further by deleting unused libraries etc from the node_modules.
@mtford90 Any chance you still have a copy of that layer? That link has unfortunately expired.
After a frustrating couple of days here is the layer I came up with for lambdas running 10.15: https://dropfile.nl/get/hK96J
It's quite large (unzips to 159mb...) but thankfully still remained within the limits for my lambda. Might be possible to reduce the size further by deleting unused libraries etc from the node_modules.
Can you share the copy of your layer again? The link has been expired. Thanks a lot.
Most helpful comment
@mtford90 Any chance you still have a copy of that layer? That link has unfortunately expired.