Assumes your Lambda handler (eg index.js
, app.js
, etc) is in the current
directory and you've already run npm install
locally (ie, you have
./node_modules
already) – the OS you ran it on shouldn't matter.
This will reinstall any native module binaries, with our current directory mounted as
/var/task
, which mirrors where it mounts in Lambda
docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 npm rebuild --update-binary
# OR
docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs10.x npm rebuild --update-binary
Instructions differ for nodejs10.x
because node-canvas has some dependencies
that don't exist there, because it's running on (a very slim) Amazon Linux 2
mkdir ./lib
docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs10.x \
cp /usr/lib64/libmount.so.1 /usr/lib64/libblkid.so.1 /usr/lib64/libuuid.so.1 \
/var/task/lib/
You can then test that it works (assumes a handler()
function in index.js
):
docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10 index.handler
# OR
docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs10.x index.handler
You should then be able to zip up the local directory and deploy to your Lambda!
You can bundle up any of these dependencies as a layer too.