DEV Community

Burke Holland
Burke Holland

Posted on

How to migrate a traditional Express API to Serverless and save tons of money

One of the key tenants of Serverless is that you only pay for what you use. You pay for the bandwidth and compute that is used when your function is called and nothing more. Without serverless, applications just run all the time and, well, it's kinda wasteful.

You can think of Serverless like this faucet...

water faucet

You have water faucets like this one in your house. One way for that faucet to work is for water to just come out all the time. It's always on and whenever you need a drink, you just walk over and fill up your cup. But we don't do that. Why? Because it's wasteful. Instead, we turn the water on when we need it and off when we don't. We only pay for the water we use.

Serverless uses the same concept. Whenever a request is made, the function is loaded into memory and then executed. When the function is not running, it goes dormant and you are not charged for it. This means that it's going to be far cheaper to use Serverless than a traditional application hosting solution.

In this video, I'll walk you through moving an API that's running in a traditional web server model with Express over to Serverless.

Here's what we go over in the video...

  • 00:19 - Walkthough of existing project (available on Github)
  • 01:27 - Create new Serverless project
  • 02:26 - Create a new HTTP Function
  • 02:47 - Add a function to read from the database
  • 04:16 - Testing locally
  • 04:47 - Create and test the rest of the CRUD functions - Create, Update and Delete
  • 07:35 - Create a new Functions App in Azure
  • 08:35 - Deploying code to the Function App in Azure
  • 09:20 - Add environment variables
  • 09:54 - Testing deployed Function App with Postman
  • 10:28 - Using proxies to create RESTful URL's
  • 14:30 - Pointing the React project at the new endpoint
  • 15:23 - Enabling CORS

👉 Download Source From Github

Additional Requirements...

Top comments (2)

Collapse
 
kamalhm profile image
Kamal

Nice, this is definitely on my list of things to do

Collapse
 
kayis profile image
K

Does Azure offer something like
github.com/awslabs/aws-serverless-... ?