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 logic unit for easier management, deployment, and sharing of resources. You can create a .NET or JavaScript app.

  1. Select the Create a resource button found on the upper left-hand corner of the Azure portal, then select Compute > Function App.

    Create a function app in the Azure portal

  2. Use the function app settings as specified in the table below the image.

    Define new function app settings

    Setting Suggested value Description
    App name Globally unique name Name that identifies your new function app. Valid characters are a-z, 0-9, and -.
    Subscription Your subscription The subscription under which this new function app is created.
    Resource Group myResourceGroup Name for the new resource group in which to create your function app.
    OS Windows Serverless hosting on Linux is currently in preview. For more information, see this considerations article.
    Hosting plan Consumption plan 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 only pay for the time your functions run. When you run in an App Service plan, you must manage the scaling of your function app.
    Location West Europe Choose a region near you or near other services your functions access.
    Runtime stack Preferred language Choose a runtime that supports your favorite function programming language. Choose .NET for C# and F# functions.
    Storage 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 may contain numbers and lowercase letters only. You can also use an existing account, which must meets the storage account requirements.
    Application Insights Default Creates an Application Insights resource of the same App name in the nearest supported region. By expanding this setting, you can change the New resource name or choose a different Location in an Azure geography where you want to store your data.
  3. Select Create to provision and deploy the function app.

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

    Define new function app settings

  5. 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.

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 will need to install the durable-functions npm package.

  1. Select your function app's name, followed by Platform Features, then Advanced tools (Kudu).

    Functions platform features choose Kudu

  2. Inside the Kudu console, select Debug console then CMD.

    Kudu debug console

  3. 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.1.2"
      }
    }
    

    Kudu upload package.json

  4. 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. Expand your function app and click the + button next to Functions. If this is the first function in your function app, select In-portal then Continue. Otherwise, go to step three.

    Functions quickstart page in the Azure portal

  2. Choose More templates then Finish and view templates.

    Functions quickstart choose more templates

  3. In the search field, type durable and then choose the Durable Functions HTTP starter template.

  4. When prompted, select Install to install the Azure DurableTask extension any dependencies in the function app. You only need to install the extension once for a give function app. After installation succeeds, select Continue.

    Install binding extensions

  5. After the installation completes, name the new function HttpStart and choose Create. The function created is used to start the orchestration.

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

  7. 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 Copy the URL. You use this URL to start the HelloSequence function.

  2. Use an HTTP tool like Postman or cURL to send a POST request to the URL that you copied. The following example is a cURL command that sends a POST request to the durable function:

    curl -X POST https://{your-function-app-name}.azurewebsites.net/api/orchestrators/HelloSequence
    

    In this example, {your-function-app-name} is the domain that is the name of your function app. 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://..."
    }
    
  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