Introducing Thaumaturgy
AWS Lambda lets you use Node modules, but you have to include them in your Zip file when you upload it. It won’t grab modules via NPM or anything like that.
The problem is that AWS Lambda is running on an Amazon Linux install, so some Node modules won’t work if you’ve built them on your own machine running Windows, OS X, or just a different version of Linux.
To fix this problem, you’d have to spin up an EC2 instance running Amazon Linux, install Node/NPM, copy your code over to the new instance, ‘npm install’, then copy the contents back to your box, THEN create your Lambda zip. It was a pain.
So I made Thaumaturgy. It’s a command line tool that creates an AWS Lambda whose sole purpose is to build Node modules for you.
Let’s say you need to build mysql2. You can build it with Thaumaturgy like this:
thaumaturgy build mysql2:0.15.8
That will spin up the Thaumaturgy Lambda and tell it to grab mysql2 from NPM, build it, and store the results in S3 as a Zip file. If you’d prefer, you can use the ‘ — download’ flag to tell Thaumaturgy to download the results for you automatically.
You can have Thaumaturgy build a list of packages, or even just read a package.json file and build all the dependencies in it.
Happy Lambda-ing.