A Lap Around Functions 2.0

|  Posted: October 25, 2018  |  Categories: Azure

You might be familiar with Azure Functions, a capability in Azure to run small pieces of code. Microsoft launched Azure Functions in early 2016 as a preview, and it became generally available mid-November of 2016. Now almost two years later Microsoft made Azure Functions 2.0 available. In this blog post, we go a lap around this second version of Azure Functions. Here you get a look at new UI changes, templates, development, DevOps, and future roadmap.

Introducing Azure Functions 2.0

The new version of Azure Functions is available with an SLA of 99.95% – meaning that functions running on a consumption plan will run 99.95% of the time after the trigger is successfully fired, or on an app service plan, the compute will be available 99.95% of the time. Furthermore, you can benefit from:

  • running functions locally in environments like Windows, Mac, and Linux,
  • host the runtime outside of the function service in for instance on kubernetes or IoT Edge and more hosting options are coming.

The V2.0 function is, according to the blog post about the announcement of the availability, more performant, as you can develop function with .NET Core 2.1. Dot net core is a free and open-source managed computer software framework for various operating systems such as Microsoft Windows, Linux, and Apple macOS. This framework consists of CoreCLR, a complete runtime implementation of the CLR – a Virtual Machine that manages the execution of .NET programs. Thus Functions V2 targets .NET core and is cross-platform, while V1 only supports the full .NET framework.

New language support

With the new version of Functions, Non-.NET languages now works from a language worker model, allowing better version support and iteration. Microsoft is currently building support for Python 3.6 for the V2 runtime. As this language is a good fit for data manipulation, machine learning, automation, and scripting scenarios. The V2 runtime now supports JavaScript (Node 8 and 10), Java 8 (preview), and .NET Core 2.

Source: https://azure.microsoft.com/en-us/blog/introducing-azure-functions-2-0/

New language support

Programming model shift

The new version of Functions brings changes to how bindings and integrations work with the code. Bindings are now extensions, simple packages that you can install with the Function tooling. By decoupling the bindings, Microsoft will allow bindings (and their dependencies) to be versioned independently of the core runtime, which means you have more control over your application and how it runs, especially as the services on which your app depends continue to evolve. Note that the core HTTP and timer do not have extensions available.

The registrations of extensions in the portal are different for V2 runtime than for V1. You have to explicitly register an extension.

Programming model shift

In a code editor like Visual Studio, you register the extensions with the available NuGet tools, while with Visual Studio Code you can use the .NET Core CLI.

Developing Azure Functions 2.0

You can develop Functions in various ways by using a code editor like Visual Studio or Visual Code, and in a browser. When you create a Function App, the container for one or more functions, you will see the following screen when you want to create a function.

Developing Azure Functions

Thus, UI change comes with the new version. Note that the default runtime for a Function App is 2.0, and when you revert to V1 through the Function App settings, you can use the old UI. You can return to V1 for a Function App in the portal before you have added a function. Once you create a function for the V2 runtime, you cannot return.

In-portal experience

You can build functions quickly using the portal and when experimenting or for a proof of concept. However, when developing production-ready functions, it is better to create them in a code editor and push it through VSTS CI/CD pipelines.

In a Function App V2 runtime, you can create a function in the browser, selecting In-portal and click continue. Next, you can choose Webhook + API, Timer or More templates.

Portal Experience

Through the More templates… option you can access other function templates and search for the template you need. For instance, if you select the Azure Queue Storage trigger, you will first need to install the extensions, which may take a few minutes. Next, you provide a name, specify the queue name, and storage account connection string, and click create. Subsequently, you see some default code similar as with Functions V1, and you can enhance, test, and add other integrations to it.

In-portal experience

The in-portal experience provides you a way to build a function in minutes and to try some code out quickly. However, you do not have any intelli-sense or debug support available like with a code-editor.

Code editor experience

The best option for developing production-ready Azure functions is through using a code editor like Visual Studio, or other supported code editors. For instance, in Visual Studio Code you can through the Azure tab see your existing functions or add a new function.

Code editor experience

In Visual Studio you can create a new FunctionApp project for version 1 or 2 runtimes and add a function to it. Subsequently, you can develop your function, debug, and test it locally.

FunctionApp

With the local test and debug capabilities, you can create a robust function and push it to a code repository like GitHub or VSTS.

Furthermore, with the second version of Functions, the product team has expanded the integration with Azure Application Insights to give more visibility into distributed tracing. Dependencies with other functions are automatically tracked, and cross-resource connections are automatically correlated across a variety of services. Moreover, these dependencies are visualized on the Application map, allowing you to understand how components interact with each other – and you can drill into individual executions to diagnose issues.

Application Map

Generally, Application Insights is a must have tool for development of any function with its rich feature set.

Azure Serverless Community Library

As a developer, you have another option of creating functions. Through the quickstart in the in-portal experience, you can access the Serverless Community Library and choose from a set of pre-built functions.

Azure Serverless Community Library

If you, for instance, choose the Blob: Image Resize you click Repo, which brings you to the GitHub page of the creator of this function. From the GitHub page, you can deploy the function to Azure. Once the deployment is successful, you can try the function out and examine its behavior.

Durable Functions

Durable functions are an extension of Azure Functions and allow you to write stateful functions. It is an implementation of the Durable Task Framework. Furthermore, in the Functions service in Azure – the state management is abstracted away through an async /await allowing you to write orchestration logic in code. Moreover, the runtime makes sure the state is durable even if the VM running the function in restarted or the function gets recycled. With the release of Functions V2.0 you as a developer also have access to durable function templates.

Durable Functions

You can with durable functions chain functions together with a separate orchestrator function to handle the workflow. This orchestrator function controls the flow and sleeps while one of the activity functions run.

DevOps Experience

You can push the function once it is ready through the code editor directly to Azure or VSTS or another repository and deploy your function using build and release templates. Within the Function App, you now can also configure how you would like to build and deploy your function using the deployment center. This new addition in functions enables you to tie your repository directly to the Function App and thus deploy your function straight away.

Deployment Center

You can find the deployment center through the platform settings of the Function App. Within the deployment center, you select your source control services such as VSTS, GitHub, DropBox, or BitBucket. Next, you specify the repository where your function resides. For instance, with VSTS you specify your VSTS account, project, repository, and branch. Next, you will see a summary, and you can finish the setup.

Deployment Center

The deployment will then start straight away with the built-in Kudu as a build server – also responsible for the deployment.

Deployment Center

Moreover, you can follow the progress during build and deployment by examining the logs. Note that you will need to set SCM_COMMAND_IDLE_TIMEOUT in the application setting to 600 (10 minutes) or higher to prevent Kudu from timing out. The build will stop after 60 seconds if you do not have this value specified.

Deployment Center

Within the logs, you can examine the build and deployment of your function to the Function App. The statements in the log look similar to what you would see an output of a build and release template in VSTS (see also the blog post about leveraging Azure Functions). Once it is complete, you will see the function appear and is ready for use.

Deployment Center

To conclude the deployment center allows you with a way to deploy a function from a repository directly.

The Future Roadmap

With Functions 2.0 Microsoft has set a course for more innovation for Azure Functions. The product teams plan to expand development stacks and hosting options for Azure Functions. A preview of the Consumption plan for Functions built on top of the Linux OS is now available. This enables you to organize functions on Linux and Mac. Furthermore, the team will bring more languages to the Functions with the earlier mentioned Python 3.6 first.

Wrap up

The new version of Azure Functions is a step forward in its evolution. The developer and operation experiences have improved. The support for dot net core is crucial in supporting other platforms and brings new ways of hosting functions. The future looks bright for Azure Functions!

Serverless360 is a one platform tool to operate, manage and monitor Azure Serverless components. It provides efficient tooling that is not and likely to be not available in Azure Portal. Try Serverless360 free for 30 days!

Serverless360-Free-Trial

Author: Steef-Jan Wiggers

Steef-Jan Wiggers is Azure Technology Consultant at Codit, is all in on Microsoft Azure, IoT, Integration, and Data Science. He has almost 20 years’ experience in a wide variety of scenarios such as custom .NET solution development, overseeing large enterprise integrations, designing and building API's and cloud solutions, managing projects, experimenting with data, SQL Server database administration, and consulting. Steef-Jan loves challenges in the Microsoft playing field combining it with his domain knowledge in energy, utility, banking, insurance, healthcare, agriculture, (local) government, bio-sciences, retail, travel, and logistics. He is very active in the community as a blogger, book author, InfoQ editor, and global public speaker. For these efforts, Microsoft has recognised him as a Microsoft MVP for the past nine years. Steef-Jan's can be found on twitter at @SteefJan.