Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-canvas build for AWS Lambda

I'm a Linux & node noob. I'm trying to run FabricJS (which requires node-canvas) in AWS Lambda. I've been able to follow the instructions to get up and running on an AWS Linux EC2, however, Lambda has me at my wits end. Anyone have any tips or pointers on how to get this compiled for AW Lambda?

like image 778
jDud Avatar asked Sep 24 '26 16:09

jDud


1 Answers

I found this issue in the Node Canvas GitHub site. The questioner was trying to run FabricJS in Lambda as well. Here is the relevant section with an answer:

  1. Make sure you're compiling this on the same AMI that lambda currently uses: http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

  2. Lambda runs at /var/task (that's the path when you unzip), so something.so at the root of the zip file will be at /var/task/something.so.

We then want to build our libraries using an "rpath":

   export LDFLAGS=-Wl,-rpath=/var/task/
  1. Compile libraries according to: https://github.com/Automattic/node-canvas/wiki/Installation---Amazon-Linux-AMI-%28EC2%29

You may want to set the prefix= ~/canvas to have all the files in one place.

  1. Install node-canvas with npm

  2. cd node_modules/canvas; node-gyp rebuild

  3. mkdir ~/pkg and cp the .so files (~/canvas/lib/*.so) there, using -L to dereference symlinks.

  4. scp the pkg directory to the local lambda folder, possibly putting the files in the right places. (.so in root, node_modules/canvas with other libs). You'll probably want to rearrange this.

like image 91
Jorriss Avatar answered Sep 27 '26 06:09

Jorriss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!