Create Durable Functions using the Azure portal

The Durable Functions extension for Azure Functions is provided in the NuGet package Microsoft.Azure.WebJobs.Extensions.DurableTask. This extension must be installed in your function app. This article shows how to install this package so that you can develop durable functions in the Azure portal.

Note

Create a function app

You must have a function app to host the execution of any function. A function app lets you group your functions as a logical unit for easier management, deployment, scaling, and sharing of resources. You can create a .NET or JavaScript app.

  1. From the Azure portal menu or the Home page, select Create a resource.

  2. In the New page, select Compute > Function App.

  3. On the Basics page, use the function app settings as specified in the following table:

    Setting Suggested value Description
    Subscription Your subscription The subscription under which you'll create your new function app.
    Resource Group myResourceGroup Name for the new resource group in which you'll create your function app. You should create a new resource group because there are known limitations when creating new function apps in an existing resource group.
    Function App name Globally unique name Name that identifies your new function app. Valid characters are a-z (case insensitive), 0-9, and -.
    Publish Code Option to publish code files or a Docker container.
    Runtime stack Preferred language Choose a runtime that supports your favorite function programming language. In-portal editing is only available for JavaScript, PowerShell, TypeScript, and C# script. C# class library, Java, and Python functions must be developed locally.
    Version Version number Choose the version of your installed runtime.
    Region Preferred region Select a region that's near you or near other services that your functions can access.
  4. Select Next : Hosting. On the Hosting page, enter the following settings:

    Setting Suggested value Description
    Storage account Globally unique name Create a storage account used by your function app. Storage account names must be between 3 and 24 characters in length and can contain numbers and lowercase letters only. You can also use an existing account, which must meet the storage account requirements.
    Operating system Windows An operating system is pre-selected for you based on your runtime stack selection, but you can change the setting if necessary. In-portal editing is only supported on Windows.
    Plan Consumption (Serverless) Hosting plan that defines how resources are allocated to your function app. In the default Consumption plan, resources are added dynamically as required by your functions. In this serverless hosting, you pay only for the time your functions run. When you run in an App Service plan, you must manage the scaling of your function app.
  5. Select Next : Monitoring. On the Monitoring page, enter the following settings:

    Setting Suggested value Description
    Application Insights Default Creates an Application Insights resource of the same App name in the nearest supported region. By expanding this setting or selecting Create new, you can change the Application Insights name or select a different region in an Azure geography where you want to store your data.
  6. Select Review + create to review the app configuration selections.

  7. On the Review + create page, review your settings, and then select Create to provision and deploy the function app.

  8. Select the Notifications icon in the upper-right corner of the portal and watch for the Deployment succeeded message.

  9. Select Go to resource to view your new function app. You can also select Pin to dashboard. Pinning makes it easier to return to this function app resource from your dashboard.

    Screenshot of deployment notification.

By default, the function app created uses version 2.x of the Azure Functions runtime. The Durable Functions extension works on both versions 1.x and 2.x of the Azure Functions runtime in C#, and version 2.x in JavaScript. However, templates are only available when targeting version 2.x of the runtime regardless of the chosen language.

Install the durable-functions npm package (JavaScript only)

If you are creating JavaScript Durable Functions, you'll need to install the durable-functions npm package:

  1. From your function app's page, select Advanced Tools under Development Tools in the left pane.

    Functions platform features choose Kudu

  2. In the Advanced Tools page, select Go.

  3. Inside the Kudu console, select Debug console, and then CMD.

    Kudu debug console

  4. Your function app's file directory structure should display. Navigate to the site/wwwroot folder. From there, you can upload a package.json file by dragging and dropping it into the file directory window. A sample package.json is below:

    {
      "dependencies": {
        "durable-functions": "^1.3.1"
      }
    }
    

    Kudu upload package.json

  5. Once your package.json is uploaded, run the npm install command from the Kudu Remote Execution Console.

    Kudu run npm install

Create an orchestrator function

  1. In your function app, select Functions from the left pane, and then select Add from the top menu.

  2. In the search field of the New Function page, enter durable, and then choose the Durable Functions HTTP starter template.

    Select Durable Functions HTTP starter

  3. For the New Function name, enter HttpStart, and then select Create Function.

    The function created is used to start the orchestration.

  4. Create another function in the function app, this time by using the Durable Functions orchestrator template. Name your new orchestration function HelloSequence.

  5. Create a third function named Hello by using the Durable Functions activity template.

Test the durable function orchestration

  1. Go back to the HttpStart function, choose Get function Url, and select the Copy to clipboard icon to copy the URL. You use this URL to start the HelloSequence function.

  2. Use a secure HTTP test tool to send an HTTP POST request to the URL endpoint. This example is a cURL command that sends a POST request to the durable function:

    curl -X POST https://{your-function-app-name}.chinacloudsites.cn/api/orchestrators/{functionName} --header "Content-Length: 0"
    

    In this example, {your-function-app-name} is the domain that is the name of your function app, and {functionName} is the HelloSequence orchestrator function. The response message contains a set of URI endpoints that you can use to monitor and manage the execution, which looks like the following example:

    {  
       "id":"10585834a930427195479de25e0b952d",
       "statusQueryGetUri":"https://...",
       "sendEventPostUri":"https://...",
       "terminatePostUri":"https://...",
       "rewindPostUri":"https://..."
    }
    

    Make sure to choose an HTTP test tool that keeps your data secure. For more information, see HTTP test tools.

  3. Call the statusQueryGetUri endpoint URI and you see the current status of the durable function, which might look like this example:

        {
            "runtimeStatus": "Running",
            "input": null,
            "output": null,
            "createdTime": "2017-12-01T05:37:33Z",
            "lastUpdatedTime": "2017-12-01T05:37:36Z"
        }
    
  4. Continue calling the statusQueryGetUri endpoint until the status changes to Completed, and you see a response like the following example:

    {
            "runtimeStatus": "Completed",
            "input": null,
            "output": [
                "Hello Tokyo!",
                "Hello Seattle!",
                "Hello London!"
            ],
            "createdTime": "2017-12-01T05:38:22Z",
            "lastUpdatedTime": "2017-12-01T05:38:28Z"
        }
    

Your first durable function is now up and running in Azure.

Next steps