-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build for AWS Lambda #680
Comments
This is actually a use case for me as well. I hope to try this this weekend and will let you know what I find. I think you'll have to bundle the SOs and change bindings.gyp to point to them. |
Zach, I'd be so grateful! On Thu, Nov 26, 2015 at 12:20 AM, Zach Bjornson notifications@github.com
|
Didn't find time this weekend, and not sure when I'll get to this. If you want to try this on your own, you might check out the commits relating to the third bullet point here: #571 |
+1 I'm also interested in this. |
Also related: #641 (although they're not statically linking). You might find some good stuff in the forks from the people commenting there and in 571. |
+1 I'm also interested in this. |
I was able to compile node-canvas and get it running on lambda by building dynamic and using rpath. Since lambda always runs in the same /var/task this makes it:
and then build normally. You should also make sure you're compiling on the same AMI environment that lambda currently uses: http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html |
@mankins could you provide some more info on how you dynamically build node-canvas? |
Hey @jalieven here's some notes I made:
We then want to build our libraries using an "rpath":
You may want to set the prefix= ~/canvas to have all the files in one place.
Good luck! |
@mankins many thanks for your notes. Works like a charm! |
@mankins Can you provide more details about the process?
My file structure (the zip that I upload to AWS Lambda) has the next structure:
In the AWS AMI instance that I am using to generate the zip file (same than you provide in your link), if I go to canvasexample/node_modules/canvas, and execute
The result that I get is:
That I guess is not correct, because (If I understand), libpng16.so.16 and the other dependencies should point to my pkg folder (may be something like "/var/task/pkg/libpng16.so.16") , that is the same I will upload to Lambda, and same that would be executed, right? (I also tried to follow another similar issue in Package pre-compiled binaries with node-canvas for downstream consumers #641. Any help is very very welcome! Thank you very much! |
It sounds like you need to use the -rpath=/var/task/ of -rpath=/var/task/pkg ... you're basically baking in a search path for dynamic libs (.so) and so if you put them in pkg, you'll need to compile them that way. |
Thanks! I arranged to make it work in the way you were describing. I will continue playing with this "rpath" option! Thanks again! |
I followed the process outlined by @mankins and created a GitHub repo with the compiled shared object (see |
@mankins I'm sure i'm missing something very basic, but when I follow those instructions I don't seem to end up with any .so files in the lib directory, just .js ones. Any pointers would be great. here is the console output...
|
@ncgonz doesn't look like you're compiling the libraries. (You missed the first step?) Have a look at @webseed's repo https://github.com/WebSeed/node-canvas-aws-lambda-example where it's been done for us. |
@mankins I looked into using that, he seems to have compiled against node version 0.10, which I cannot use. I have a dependency on jsdom, which requires node 4.3. I finally got everything compiled last night, and now have everything running on lambda. Hooray! Thanks for the pointers |
Just created a gulp plugin to automate deployment of node-canvas in aws lambda which would handle both nodejs 0.10 and nodejs 4.3. jic if someone needs, https://www.npmjs.com/package/aws-lambda-node-canvas. |
Hi...I am having the same problem. Am I missing something here? @mankins : I just couldn comprehend this "Make sure you're compiling this on the same AMI that lambda currently uses". Where can I get this info about the AMI that my Lambda function uses? Do I get a console for AMI where I can compile? I have a few EC2 instances.Do I have to create an AMI for a particular EC2 instance? How to link my Lambda function with this AMI? I know this may sound silly but I am really confused . |
@abhi06991 you need to create EC2 instance with ami that lambda currently uses (http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html) then ssh there and compile your thing |
Hey guys, I followed the instructions and everything is working fine except Font Rendering. No font is rendering and Paths to font folders are correct,I have verified it. I have included the following libcairo.so.2 Do I have to include some other |
@abhi06991 you probably want to do |
@navihtot I found your how-to notes super helpful, thanks! |
@timsvoice np, glad that it helped somebody :) |
Anyone managed to recently run everything successfully in Lambda? I'm using node-canvas through chartjs-node to render charts, I'm almost there but stuck on font rendering... |
I was able to render custom fonts and everything. What is your issue?
…On Jan 9, 2018 6:19 AM, "Jonathan Gautheron" ***@***.***> wrote:
Anyone managed to recently run everything successfully in Lambda? I'm
using node-canvas through chartjs-node to render charts, I'm almost there
but stuck on font rendering...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#680 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAWOAZBF0efikapoBKChBaQuHm-A1LPGks5tI0tOgaJpZM4Gprvw>
.
|
Basically the text is rendered as blocks, as if the font was not found. |
Try using __dirname to prefix the path and make sure its included in your
deployable.
Try your script locally
…On Jan 9, 2018 6:29 AM, "Jonathan Gautheron" ***@***.***> wrote:
Basically the text is rendered as blocks, as if the font was not found.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#680 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAWOAfSdhhen74APZ5ssA7Ex0WiOkxmLks5tI02ogaJpZM4Gprvw>
.
|
By the way, in case anyone needs it, here's the full list of commands I ran in a Linux AMI (the one that https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html shows, currently 6.10) Steps to build node-canvas for Lambda usage
After that, you can |
I don't really understand why using "-rpath" and rebuilding the libraries from source should be required. According to the Lambda Documentation, I took the Lambda AMI and spun up a VM. I installed Node and development tools: sudo yum groupinstall "Development Tools" -y
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash
# Exit session and reopen here to make nvm available
nvm install 6.10 Then I installed node-canvas as you normally would: sudo yum install cairo-devel libjpeg-turbo-devel giflib-devel pango-devel -y
npm install canvas@next Then I copied the system libraries from
I added an index.js to test Canvas with: let
{createCanvas} = require("canvas");
function hello(event, context, callback) {
let
canvas = createCanvas(200, 200),
ctx = canvas.getContext('2d');
// Write "Awesome!"
ctx.font = '30px Impact';
ctx.rotate(0.1);
ctx.fillText('Awesome!', 50, 100);
// Draw line under text
let
text = ctx.measureText('Awesome!');
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.beginPath();
ctx.lineTo(50, 102);
ctx.lineTo(50 + text.width, 102);
ctx.stroke();
callback(null, '<img src="' + canvas.toDataURL() + '" />');
}
module.exports = {hello}; And a
The resulting project structure:
I downloaded this entire folder to my local machine. Then I called |
We could technically close this ticket and just leave that last comment as instructions for use in Lambda. I went for the manual build because I didn't know where to take the .so and libs from. That is way easier, thanks @thenickdude |
I've added those instructions to the Wiki now: https://github.com/Automattic/node-canvas/wiki/Installation---AWS-Lambda |
Closing since @thenickdude added instructions (thank you!). |
Updated link is https://github.com/Automattic/node-canvas/wiki/Installation%3A-AWS-Lambda, which also includes the encouraging note:
and cross-references #1231 |
Is it still the case that this works "out-of-the-box" I'm getting the following Lambda error: {
"errorType": "Error",
"errorMessage": "libuuid.so.1: cannot open shared object file: No such file or directory",
"trace": [
"Error: libuuid.so.1: cannot open shared object file: No such file or directory",
" at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)",
" at Module.load (internal/modules/cjs/loader.js:600:32)",
" at tryModuleLoad (internal/modules/cjs/loader.js:539:12)",
" at Function.Module._load (internal/modules/cjs/loader.js:531:3)",
" at Module.require (internal/modules/cjs/loader.js:637:17)",
" at require (internal/modules/cjs/helpers.js:22:18)",
" at Object.<anonymous> (/var/task/node_modules/canvas/lib/bindings.js:3:18)",
" at Module._compile (internal/modules/cjs/loader.js:701:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)",
" at Module.load (internal/modules/cjs/loader.js:600:32)",
" at tryModuleLoad (internal/modules/cjs/loader.js:539:12)",
" at Function.Module._load (internal/modules/cjs/loader.js:531:3)",
" at Module.require (internal/modules/cjs/loader.js:637:17)",
" at require (internal/modules/cjs/helpers.js:22:18)",
" at Object.<anonymous> (/var/task/node_modules/canvas/lib/canvas.js:9:18)",
" at Module._compile (internal/modules/cjs/loader.js:701:30)"
]
} Here's how to reproduce it: 1. Spin up an Amazon Linux 2 AMI:I installed this one. amzn2-ami-hvm-2.0.20190313-x86_64-gp2. Then connect to the server over ssh. 2. Install node 10
3. Install Serverless
4. Create project directory and install Canvas
5. Create Lambda handler
|
For some reason the /lib64 directory on Lambda for Amazon Linux 2 (Node 10) is incredibly sparse, much more empty than in the corresponding AMI they've published, which doesn't make sense to me. I had to bundle the following libraries from Amazon Linux 2 with my function:
Notably, libuuid is not even included in the prebuilt Canvas. Is the Amazon Linux 2 image currently deployed on Lambda actually broken? |
@thenickdude libuuid is included on my AMI ll /usr/lib64/ | grep libuuid
lrwxrwxrwx 1 root root 16 Mar 8 19:58 libuuid.so.1 -> libuuid.so.1.3.0
-rwxr-xr-x 1 root root 20056 Jul 26 2018 libuuid.so.1.3.0 What is that size of all that? Copying all these files into your project will put you dangerously close the the max size of a Lambda function (250 MB). |
Yes, it's in the AMI but it's not in the actual Lambda runtime environment. Run this on Lambda Node 10.x: const fs = require('fs');
exports.handler = async (event, context) => {
return fs.readdirSync("/usr/lib64").filter(p => p.match(/\.so/)).sort().join("\n");
}; This is the result:
The required libraries from my last post are about 100MB. |
@thenickdude Thanks for your insight on this. I created a Lambda Layer which will address this issue. |
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?
The text was updated successfully, but these errors were encountered: