tomdale / lambda-packager

Builds dependencies for Node.js Lambda functions
145 stars 14 forks source link

Cannot compile node-gyp modules on Lambda #6

Open redbugz opened 7 years ago

redbugz commented 7 years ago

I was able to get around the deploy issues and get this deployed to Lambda using some of the code from the forks, but once it is deployed, I cannot get it to correctly compile a node-gyp module like contextify as an example.

Perhaps it is because I am using the new 4.3.2 Node.js runtime on Lambda and maybe they tightened down what it can do. First, npm and node-gyp both want to put files in your $HOME directory, which is not writeable in current Lambda, resulting in EROFS errors. So setting $HOME=/tmp seemed to fix that problem. Then it tried to actually compile something and now it can't find g++ make: g++: Command not found and I haven't been able to find a way to get around that yet.

I have an older instance deployed on the 0.10.46 Node.js runtime, and I get this error there:

"/var/task/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:54",
        "    throw new Error(",
        "          ^",
        "Error: node-gyp requires that the user's home directory is specified in either of the environmental variables HOME or USERPROFILE",

which could probably be fixed by setting $HOME=/tmp, but that runtime is going away, so I don't really want to spend time getting it to work.

Has anyone gotten this approach to work, using Lambda to compile node_modules for Lambda? Or is EC2 really the only approach?

AlexisNo commented 7 years ago

I tried to make it work with the same solution that the one provided by this repo, but I had the same problem when trying to install bcrypt.

I did not want to use an EC2 instance and ended creating this docker image: https://github.com/myrmex-org/docker-lambda-packager https://hub.docker.com/r/myrmex/lambda-packager/

The solution may seem a little hacky but I managed to deploy a Lambda with a dependency to bcrypt with the two node.js runtimes.