0 votes
1 view
in AWS by (15.2k points)

I'm using AWS Lambda, which involves creating an archive of my node.js script, including the node_modules folder and uploading that to their infrastructure to run.

This works fine, except when it comes to node modules with native bindings (using node-gyp). Because the binding complied and project archived on my local computer (OS X), it is not compatible with AWS's (Amazon Linux) servers.

How can I cross-compile/install a node module (specifically, node-sqlite3) so when I upload it to another server arch it runs?

1 Answer

0 votes
by (36.2k points)

There is a simple workaround for this, not the solution to your question but can solve the problem.

Vagrant can be used for this. You can create and configure VMs in a matter of seconds.

  1. Find an OS image that resembles Amazon's Linux distro (Fedora, CentOS, others that use yum as package manager)
  2. Use a simple configuration script that, when run by Vagrant on machine startup, will run npm install (optionally it might also remove the node_modules folder before to ensure a clean installation)
  3. For further comfort, the script can also create the zip file for deployment
  4. Once the installation finishes, the script can shut down the Virtual Machine to avoid excess consumption of system resources
  5. Deploy!

It might require some tuning if the linked libraries are not at the same place on the target machine but generally, this seems to me like the best and quickest solution.

...