ESP vs Azure Functions

If you’re looking at getting started with Azure, we’ve put together a comprehensive “Hello, World’ guide. In addition to Azure, we’ve put together a no-frills comparison of the getting started experience from the developer perspective. Learn more, build more and check out the latest from Val Karpov in this latest installment of our Developer Spotlight Series.

Azure Functions are Microsoft Azure’s equivalent to AWS Lambda. Like Lambda, Azure Functions let you write custom functions and expose them via an HTTP interface using Azure API Management. Express Serverless Platform offers a similar stack that lets you write Node.js APIs and expose those APIs through Express Gatewaywithout vendor lock in. In this article, I’ll walk through setting up a rudimentary function and gateway in both Express Serverless Platform and Azure and discuss the tradeoffs of using one or the other.

Azure Functions

Log in to the Azure Portal and click “Create a resource.” In Microsoft Azure, “resource” is a very broad term that applies to any manageable service Azure offers you. A function, a VM, an IP address, and storage space are all distinct resources.

 

Compare Azure and Express Serverless Platform

 

Clicking on “Create a resource” will open up a new “blade” in the Azure UI. Blade is just a fancy name for a panel in the Azure UI. Click “Compute” and then “Function App” to create a new Function App. A Function App is a collection of individual functions.

 

Compare Microsoft Azure and Express Serverless Platform.

 

Once you click “Function App”, you’ll see a blade that asks you for information about your Function App. Enter in a name, but be aware that your name needs to be unique across _all_ Azure function apps, so you should prefix the name with your name. For this example, there’s no need to change any of the other options. Notice that, by default, Azure Functions run on Windows. Ideally your functions shouldn’t care about what OS they run, so long as they’re running on the right version of Node.js, but this is something to be aware of if you are using Node.js C++ add-ons compiled with node-gyp.

 

Compare Microsoft Azure with LunchBadger

 

Click “Create” and Azure will kick off creating your Function App. Click the bell icon on the upper right to look out for a notification that Azure finished creating your app.

Compare Microsoft Azure with LunchBadger

 

Once Azure has created your app, click “Go to resource” to configure your Function App.

 

 

Remember that a Function App is a collection of functions. Click the plus icon next to “Functions” to create a new function.

 

Compare Microsoft Azure with LunchBadger

 

Azure makes it easy to create a function that’s exposed via HTTP. Choose the “Webhook + API” scenario and “JavaScript” as your language, and then click “Create this function.”

 

Compare Microsoft Azure with LunchBadger

 

Azure will create a new “Hello, world” function for you. Change the code to print out the current Node.js version as well, and click “Save and run” to execute this function

module.exports = function (context, req) {
 context.log('JavaScript HTTP trigger function processed a request.');
 if (req.body.name) {
    context.res = {
    // status: 200, /* Defaults to 200 */
    body: 'Hello ' + req.body.name + ' from Node.js ' + process.version
    };
    }
    else {
    context.res = {
    status: 400,
    body: "Please pass a name on the query string or in the request body"
    };
    }
    context.done();
    };

Compare Microsoft Azure with LunchBadger
  Click on “Get function URL” to get the publicly accessible URL for your function. Azure will automatically generate a key for you so your endpoint has some rudimentary security.  
Compare Microsoft Azure with LunchBadger
  You should now be able to access your function using curl.
$ curl -H "Content-Type: application/json" -X POST -d '{"name":"curl"}' https://vkarpov15-test.azurewebsites.net/api/HttpTriggerJS1?code=OMITTED
 "Hello curl from Node.js v6.11.2"
 $

Note that, by default, Azure currently uses Node.js v6.11.2. You can configure this using 

package.json

, so you should be able to use Node.js 8 and async/await with Azure Functions.

Express Serverless Platform and Express Gateway

In Express Serverless Platform, first create a new function and name it ‘myfunction’:
LunchBadger and Express Gateway

Node.js functions in Express Serverless Platform have the same function signature as native Node.js HTTP request listeners. The function to print ‘Hello, world!’ with Express Serverless Platformis shown below. Note that the exported function must have the same name as the function name you assigned in the LunchBadger GUI.

module.exports = {
 myfunction (req, res) {
 res.end('Hello, world!');
 }
 };

Compare Microsoft Azure with LunchBadger

 

Note that this function does not have to create an actual HTTP server.Express Serverless Platform handles creating a server for you, so you can write “serverless” functions without having to actually write an express application. You do still get access to the Node.js HTTP response, so you can set HTTP headers and set the HTTP status code.

From the menu on the left, add a new gateway. This will add an Express Gateway instance to your project.

 

Compare Microsoft Azure with LunchBadger

 

Click the plus icon next to “Policies” to add a policy to the default Express Gateway pipeline. In Express Gateway, a pipeline is a sequence of policies for handling a request. Add an empty ‘proxy’ pipeline.

 

Compare Microsoft Azure with LunchBadger

 

Drag a line from your gateway to your function, and Express Serverless Platform will automatically connect your proxy policy to your function.

 

Compare Microsoft Azure with LunchBadger

 

Express Serverless Platform will also create a function endpoint for you. Keep the “paths” for your function endpoint empty for now. Click on the “settings” icon to find the publicly accessible URL for your Express Serverless Platform project.

 

Compare Microsoft Azure with LunchBadger

 

Running curl on the URL will now run your custom function and give you the “Hello, world!” text.

$ curl http://gateway-148-dev.lunchbadger.io
 Hello, World!
 $

Moving On

The combination of Express Serverless Platform and Express Gateway is a great alternative to Azure Functions if you’re looking to avoid vendor lock-in. In particular, the fact that Express Serverless Platform scaffolds out an app for you and stores it in a git repo that you can clone enables you to run your app locally or on any cloud provider. Express Serverless Platform does automatically host your app for you, but that isn’t your only option.

With Azure Functions, you can’t clone your whole stack and run it locally. You can run your functions locally, but the API Management part of the stack lives exclusively in Microsoft Azure. Azure is appealing because Microsoft is a well-established company and Azure has a proven track record of running applications at massive scale.

However, using Azure Functions means you must run your code on Azure and use Azure API Management, so you can’t run your full app locally or on another cloud provider.

 

This short video demonstrates Express Serverless Platform running on Azure. The demo utilizes a SOAP connector to interface with a legacy customer SOAP service and creates a new facade called a credit application through a model function.

 

 

 

We’ve written a complete guide towards understanding the major differences and similarities between Express Serverless Platform on Azure versus Azure Functions across multiple dimensions, including features and pricing, which is available for download from our Resources page.

Additionally, if you’re interested in more of these topics, join the live discussion on twitter @lunchbadger or @express_gateway.


   

Share Tweet Link