node-canvas-lambda icon indicating copy to clipboard operation
node-canvas-lambda copied to clipboard

More libraries required for Chart.js

Open nabilfreeman opened this issue 6 years ago • 8 comments
trafficstars

Hey there, I made a fork where the lib64 layer includes a few more libraries:

libuuid.so.1
libpixman-1.so.0
libpangoft2-1.0.so.0
libjpeg.so.62
libmount.so.1
libpango-1.0.so.0
libpangocairo-1.0.so.0
libblkid.so.1
libcairo.so.2
libfreetype.so.6
libpng.so.16

These were necessary to get Chart.js working on AWS Lambda.

I got the list from here: https://github.com/Automattic/node-canvas/issues/680#issuecomment-364627155

Fork: https://github.com/nabilfreeman/node-canvas-lambda

nabilfreeman avatar Oct 21 '19 13:10 nabilfreeman

Actually it didn't work, needed libpng16 which wasn't even on Amazon Linux 2 AMI.

I gave up and am using quickchart.io

nabilfreeman avatar Oct 21 '19 14:10 nabilfreeman

@nabilfreeman This should work with Chart.js. I recommend using https://github.com/SeanSobey/ChartjsNodeCanvas

jwerre avatar Feb 10 '20 19:02 jwerre

@nabilfreeman dude! thanks for the canvas-lib64-layer.zip, you've saved my sanity!

gligorkot avatar Jun 18 '20 04:06 gligorkot

🙌🏻

jwerre avatar Jun 18 '20 05:06 jwerre

@jwerre @nabilfreeman any of you guys tried running/getting a Node 14.x lambda layer? I'm updating our stack at the moment and charts are coming back blank - not sure what I'm doing wrong if anything.

gligorkot avatar Jul 25 '21 22:07 gligorkot

@gligorkot Did you manage to solve for Node 14?

bretto36 avatar Feb 22 '22 05:02 bretto36

@bretto36 I did manage to, but I never finalised my solution nor deployed it - it's on my list to get back to it over the next few months, but other things are taking priority at the moment. Please share your solution if you do manage to get it working 🙏

gligorkot avatar Feb 23 '22 02:02 gligorkot

So, I made it work with Node 14, by trying out some solutions from this thread here https://github.com/Automattic/node-canvas/issues/1779

What worked for me was exposing an ENV variable for the lambda runtime that's using the layer.

LD_LIBRARY_PATH: '/var/task/node_modules/canvas/build/Release'

AltanS avatar Aug 02 '22 08:08 AltanS

Hey all, I managed to get a Node 16.x lambda layer going using one of the forks from @igara and working on top of it here https://github.com/gligorkot/node-canvas-lambda

I then used the ENV variable from @AltanS above in my Lambda and voilà it all works on the latest AWS Lambda Node 16.x runtime.

Hope this helps someone if they stumble upon it.

Now I can rest for another 2 years before needing to update these again 🙂

gligorkot avatar Aug 19 '22 00:08 gligorkot

Thanks for the help @gligorkot. I'll dig into this today and see if I can't get it fixed up. Version 2 is underway!

jwerre avatar Aug 19 '22 15:08 jwerre

@gligorkot can you do me a favor and create a merge request into the development branch so I can take a look at it?

jwerre avatar Aug 19 '22 15:08 jwerre

@jwerre good work updating the main repo to the latest AWS Node.js supported version. I think this issue can now be closed, right?

The only thing I don't see in the Readme is instructions about adding an ENV Var LD_LIBRARY_PATH: '/var/task/node_modules/canvas/build/Release' as @AltanS mentioned above. Not sure if that's required with your solution now @jwerre?

This is why I love Open Source! :)

gligorkot avatar Sep 01 '22 21:09 gligorkot

@gligorkot. Yes, these issues should be resolved. You do not need to set the LD_LIBRARY_PATH since one of the paths here is opt/lib. This is the location of your layers if they are attached your function correctly. If you're continuing to have trouble check which architecture you're using: AMD or x86. If you're using x86 check out the x86-64 branch and publish from there.

git checkout x86-64
make build
make test
make publish

jwerre avatar Sep 01 '22 23:09 jwerre