Azure Functions As A Service

Amazon started this new model of service - Functions as a Service with a product called Lambda. Microsoft also announced Azure Cloud Functions in Build 2016. Google also has Google Cloud Functions which is in private preview currently.

Azure Functions

Azure Functions are an event driven, compute-on-demand experience with capabilities to implement code triggered by events occurring in any Azure or 3rd party service as well as on-premises systems. We can create Functions in a variety of languages, including JavaScript, C#, Python, and PHP, as well as scripting options such as Bash, Batch, and PowerShell. The Functions can be created as a Azure Function app in an easy-to-use web-based interface or pre-compiled code can be uploaded and triggered.

It is like a nano-service, that can respond to a event coming from a queue, a timer, SQL trigger or any event from other services. So it is a very small piece of code performing a very focused activity.

Creating a Sample Azure Function App

Search for Function App and Create a new Function App as shown below.

create

Once this is created, you will see two types of apps created, one is the Function App Service and the other is the Application Insight App.

create

Click on the App Service, you would see the QuickStart guide as shown below,

create

create

In the Function App Settings, you would see options as below, where we can configure continuous integration, authentication, API metadata and CORS for HTTP-triggered functions.

functions

In the Advanced Settings there are many more sections in the Settings Blade, which can be configured, for ex: Backups, Service Instances , Live HTTP Traffic and so on.

Settings

Click on the WebHook + API option and click Create New. You will see a boiler plate template code ready with a wizard to guide through.

code

Click on Integrate. Integrate is where you define the trigger, Input and Output bindings to storage, queues and so on.

trigger

Go back to Develop Tab, Hit Save. Click on Run, and you would see the Output and the Logs that shows what actions happened on the function.

run

You can now copy the function URL and paste in the web browser.

url

You will get the following message,

message

So append Name in the query string and we see the required output.

output

When you click the Monitoring Tab in the Function App Service, at this point in writing, you would see a Coming Soon placeholder.

soon

But there are 2 active links - Invocation Log and Live Event Stream

Live Event Stream is also called Azure Function Pulse. It is very interesting to see various graphs as the function service is invoked, a sample of which is show below.

sample

Click on Invocation Log - you will see reports as shown in Azure WebJobs.

WebJobs

As said in the beginning of this article, 2 application types are created when you create a Function App, the Function App itself and a Application Insights Service. For more graphs and reports on the Function that was created, you can deploy the Insights services and generate many more reports. When you click on the Application Insight App that was created for this function , you see the following options,

options

Click on Start Monitoring. It will take a few seconds for this extension to be installed.

extension

We need to configure and add code to get meaningful data in the Application Insights App. As of writing this article, the following bindings are supported.

bindings

Need of Azure Functions

As we are moving in the era of micro-services, nano -services are also started gaining traction. For scalability for particular piece of code, Azure Functions can play an important role such that cost and performance can be optimized.

Azure Function requests are charged per million requests, with the first one million requests free. As with other cloud resources, with Azure Functions we pay for what we use. The compute is metered based on the time the function runs to the nearest 100ms at Per/GB price and the memory size of the function space we choose. Function space size can range from 128mb to 1536mb. With the first 400k GB/Sec free.

So we pay only for the time our code runs and trust Azure to scale as required.

Read more articles on Azure:

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now