Product and service reviews are conducted independently by our editorial team, but we sometimes make money when you click on links. Learn more.

Getting Started with Microsoft Azure Functions

By - Source: Toms IT Pro

Microsoft's serverless computing product, Azure Functions, can help you with server deployments, server configuration and more.

Cloud is hard, managing servers is hard, hence a recent push by major Cloud Providers toward something called "serverless computing". This is obviously a misleading name as there is no such thing as compute without servers, because, at least in 2017, code needs to run on servers.
The actual idea behind this term is that you do not need to worry about server deployments, server hardening, server configuration and so on, but can focus on your business application, your code. The rest is taken care of by the provider.

MORE: What Is Microsoft Azure Stack?

What is Azure Functions

Microsoft's "serverless computing" product is called "Azure Functions" and is being developed as an open source product in C#. The source code can be found online

If you have already previously used Azure Web Jobs, Azure Functions will feel very familiar to you. Functions are built on Azure Web Jobs, but they take care of maintaining and managing the underlying Azure Web App for you so that you can focus on your function.

Strictly speaking you have always been able to achieve the same functionality (or similar) with Azure Web Jobs, only you had to take care of more "unnecessary noise". Web Jobs evolved into Azure Functions. As a result of this "focusing on Functions" these "serverless computing" offerings are also often, more aptly, referred to as "Functions as a Service" (FaaS).

Use cases for Azure Functions

Azure Functions are charged by the number of executions and the time it takes to execute one. Functions are triggered by external events (HTTP calls, schedules, events on Azure, etc.) and can be written in almost any scripting or developing language you want. Currently, supported languages are C#, Javascript/NodeJS, F#, PowerShell, Bash, Batch/CMD, Python and PHP. Thanks to its open source nature, you can add your favourite language to it.

Create the first Azure Function

To create our first Azure Function we head over to our Azure Portal and deploy a new "Function App". Think of a "Function App" as a logical home for one or many Functions.

You can have Azure create a new Resource Group and Storage Account (every Function App comes with its own Storage Account) or choose to select existing ones, for now this is not important.

After that Function App has been deployed we can deploy our first Function into it. Microsoft makes this very easy by offering multiple "quickstart templates" that can be deployed straight from the portal.

Clicking the "+" button next to "Functions" will bring us to a screen from where we will deploy a premade "Webhook + API" Function written in C#. For other scenarios you can select to follow any of the other options on this screen.

With a click on "Create this Function" we are brought back to the Function App and find a new Function called "HttpTriggerCSharp1", one of the pre-canned functions. We have now successfully deployed our first C# Function that can be triggered by an HTTP call. "How though?", you ask?

Copy the Function URL from "Get Function URL" and paste it into your browser. It should look something like this: 

Treat the "code" as a secret. This is used to check authorization on your Function. 
This Function accepts one parameter called "name" and the easiest way to pass this parameter in is by adding "&name=David" to the URL. You should now see a friendly greeting as a result.

You can just as easily test this Function from the portal by executing the "Test" functionality as can be seen in this last screenshot here:

The following commands will execute this Function from your command line.

Invoke-RestMethod -Method Post -Uri "https://<functionAppName><functionAppCode>&name=David"
(the Url has to be in quotes otherwise PowerShell will throw an exception)


curl https://<functionAppName><functionAppCode>&name=David