AWS Lambda Layer with node-canvas and Fabric included for ARM64 runtime
Oh! You want to make your own layer with different version!? Don't worry we got you covered
Create an EC2 instance with Amazon Linux 2, you cannot get your node-canvas running if build environment is different from lambda (tl;dr mismatch glibc version)
Future note: It's possible that you come from the future and Amazon Linux 2 is no longer active runtime for Lambda. Check your current lambda operating system at AWS Docs, if it is ping me please and i will try to update docs later
Then, install required dependencies for creating lambda layer by calling a script
./initialize.sh
If everything goes well, then you're ready to build a layer! Specifying your preferred canvas
, and fabric
version in build.sh
then execute it
./build.sh
As a final result, you should have layer.zip
at dist/
directory. Upload it to Lambda layer, and you should be ready to go.
Just add layer to Lambda function, and you should be able to use them normally
import canvas from 'canvas'
import fabric from 'fabric'
// code below
Check compiling section of node-canvas repository, try to check that is there some package were addded and initialize command does not have
Please make sure that
- You're running lambda function as arm64
- Your created EC2 instance is an arm64 instance
- Node version for your Lambda runtime, and EC2 instance are the same major version
Check this line of initizlization. You can change way to install Node here. Just make sure that you're installing arm64 version of Node, not amd64