AWS λ (Lambda) Deployments
If you have read about AWS Lambdas, you must have noticed that deployments are executed by uploading a zip file. Weird, I know. This comes with a few side effects as well.
Handling npm install
First one I noticed was when doing a quick deploy. I cloned a repository and immediately tried to upload the zip file. I attempted to run my λ and it failed. Can you tell why?
I forgot to run npm install.
Normally, when deploying an application, I take this for granted given that the build systems do this for me. When dealing with λ, you need to take care of this yourself.
Second thing I came across was how big the footprint of the λ was. My uploads were taking forever (I do have crappy internet to be fair). How can I optimize this? Simple.
npm install —production
If you are developing, you should be running tests that depend on devDependencies, right? How can you have a sane flow?
Enter node-lambda. This was built over at RebelMail by Mot before I joined. Afterwards I added some extra features and safety steps to deployments. Between those are:
- Multi-AZ deployments
- Always npm install —production on a separate folder
With these, I resolve the first issues I came across on my deployments. Also, given Multi-AZs deployments, node-lambda plays hand to hand with Lambda-Runtime.
Handling compiled dependencies
Third thing I noticed was meanwhile deploying a dependency that was compiled. I use OSX on a regular day for my development. Hence, when I uploaded the zip file, it had my dependencies for OSX. Lambda’s run on Linux. How can I solve this? First though was to use Vagrant. But I came across a simpler solution. Using my CI.
Achieving Continuous Deployments
Using a CI is extremely convenient with Lambdas. And node-lambda simplifies it. By including it as a devDependency, I can instruct my CI to run a command similar to this one:
./node_modules/node-lambda/bin/node-lambda deploy -e staging
Test, deploy, enjoy. Also my CI’s has a way better internet connection than I do ☺.
If you come across tidbits about Lambdas, you know where to find me.