Being a developer is amazing. Writing code, solving problems and thinking of ingenious solutions for complicated algorithms is what we live for. But, the grass is not always so green on this side of the fence. Sooner or later you need to get your hands dirty and deploy the app you worked so hard on. Deployments are not always easy. To be blunt, they can be incredibly hard and time-consuming. That’s what we’ll solve in this tutorial.
You can follow along from the beginning or jump to the section which interests you most, and severely hurt my feelings. 😅
Today you’ll learn how to deploy a Node.js application to AWS Lambda with the help of the Serverless Framework.
The walkthrough will also cover a real-life scenario of deploying a production version of your application, with environment variables, proper monitoring, and, of course, easy debugging. Oh, how I love seeing nice stack traces!
This tutorial will need you to have a few simple things set up already. Don’t worry, nothing special, just the basics, and I’ll link it all below for you to see, and make sure you have, before moving on.
Ready? Let’s go!
AWS Lambda is a pay-as-you-go serverless compute service. Meaning what now? Well, you just deploy your source code to AWS and they handle the rest. Amazing! No need to fiddle with servers, ssh connections, Linux or Vim. But, want to know what’s even better? It scales automatically and has absolutely no downtime. I’ll let that sink in…
The technical definition for AWS Lambda would be a Function as a Service. You deploy some code, it gets invoked, processes some input, and returns a value. Simple!
Hold up a sec. We need to mention a crucial fact. All lambda functions are stateless, meaning they cannot store persistent data. And, if I just said Function as a Service, how do we deploy a whole Node.js application to AWS Lambda?
When you think about it, it’s not that complicated. A single lambda function is essentially just a tiny Node.js runtime environment. You can run whatever you want in there. That’s what we’ll do, package up a Node.js app and send it off to AWS Lambda. Sneaky. 😉
To make this example as simple as possible, the code we’ll be deploying is just 7 lines long. However, it could be as large as any Node.js application you have in production, and it would all work like a charm. Intriguing…
In comes the Serverless Framework like a horse riding a white knight! Hold up, I may have that backward. 🤔
Anyhow, this awesome framework enables us to both develop our apps locally, just like we’re used to, but also deploy it with one simple command. Hmm… tell me more.
First thing’s first. Open up your terminal, we need to install some packages. Yay, installing stuff, love it! 😫
#serverless #aws #node.js