A Practical Guide to Azure Durable Functions — Part 1: Introduction

Everything you need to know to create a production-ready function app via Azure Durable Functions.

Allen Zhang
5 min readMay 26, 2020

--

This is the first article of this series about Azure durable functions. This series aims to provide a practical guide for devs to follow to create production-ready applications. This is a hands-on guide and it does not discuss the pros and cons of the serverless architecture.

Note: you will need to have some C# programming skills and basic knowledge of Microsoft Azure to follow along.

In this first article, we will cover:

  • create necessary resources on the Azure portal.
  • create a demo durable function via Visual Studio 2019.
  • create a basic CI/CD pipeline.

We will build on top of this demo app in the following stories.

Prerequisites

Create Azure Resources

Go to the Azure portal on a new browser tab and create a new Function App resource. Simply click through the steps, make sure to:

  • Select .NET core for runtime stack and version 3.1.
  • Choose the Consumption plan — it costs nothing when it’s not running.
  • Enable Application Insights for monitoring.

Create the Function

Open Visual Studio and search for Azure Functions on the create a new project page. Create an Azure Function project. Select an empty Azure Functions V3 (.NET core) function.

Once the project is created, right-click on the project and then Add =>New Azure Function. Name your new function DemoOrchestrator.cs.

Select Durable Functions Orchestration as the function type. You might need to wait for Visual Studio to load all function templates if this option does not show up.

The template puts all functions in the same file 😟 Let’s create some folders and files with meaningful names. And then split the function code into their own files.

That looks better! Let’s commit our new function app to your favorite source control.

Note: by default, local.settings.json is in the ignore file. But I prefer to commit it to the source control so that when a developer checks out the code, he/she can simply hit F5 and run the function app with sensible default configurations.

Create the CI/CD Pipeline

Now we can build the solution and deploy it to Azure from Visual Studio. However, in modern software development, we want to set up the CI/CD pipeline first so that our changes will be built, tested, and then deployed to the dev environment as soon as they are merged to the master branch. We’ll use Azure Devops in this article, but feel free to use your favorite tool.

Head to Azure Devops and create a project.

Navigate to Project Settings => Service connections and then create service connections for GitHub and Azure Cloud Service. We’ll use them later in the pipeline.

Note: if you choose to use Azure Devops git repository as your source control, you don’t need to add it as a service connection.

Navigate to Pipelines and hit Create Pipeline. Follow the steps to choose your repository and then configure the pipeline as .NET Core Function App to Windows on Azure. Choose the function app created on Azure earlier as the deployment target.

A .yml file with build and deploy stages should be created. If you are not familiar with yml pipelines, all these stages, jobs, and steps could be overwhelming. Don’t worry too much about it, for now. The only change I made is updating the vmImageName to ‘windows-2019’ to make sure the agent uses Visual Studio 2019 to build the project.

Now hit the Save and run button, you want to check the option to commit this yml file to the source control.

The other option is to use the classic pipeline editor to configure a separate build pipeline and release pipeline. The classic editor is easier to configure because it has a nice UI. But you lose the ability to update the pipeline via code commits (this allows the change to be peer-reviewed). The choice is yours.

If the pipeline finishes successfully, you should see two green ticks.

Now our Function App on Azure should have a deployment and functions ready to do work. Find the function app on Azure and click Functions, you should see the functions listed here.

We’ve got a working pipeline! Commit some code changes and see what happens.

Summary

At the end of this first article of the durable function series, we now have a do-nothing durable function code, an Azure function to host the application, and a pipeline to automatically build and deploy code changes to Azure.

The code can be found on GitHub.

In the next article, we will let the application do something useful and explore the dependency injection options for Azure durable functions. Stay tuned.

Here’s part 2.

--

--