Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

Create a Durable Azure Function

In this lab, we create and run an Azure Durable Function and retrieve the result of the orchestration via PowerShell.

Azure icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon Feb 28, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Log In to the Azure Portal

    Log in to the Azure Portal using the username and password supplied by the lab.

    1. Open a browser.
    2. Navigate to the provided Azure Portal URL.
    3. Use the supplied username and password to authenticate.
  2. Challenge

    Add a Durable Orchestration Function to the Function App

    Go to the overview of the provided function application service. Starting in the Azure dashboard perform the following tasks:

    1. Open the navigation menu in the upper-left of the Portal.
    2. Click All resources. Wait for the all resources list to appear.
    3. In the list, click on the app service with a name starting with fa-. This will open the overview page of the function app service.
    4. Click the Functions menu item in the navigation tree on the left of the page.
    5. Click New function near the top center of the page.
    6. From the list of trigger types, click Durable Functions orchestrator.
    7. In the New Function panel that appears on the right of the page, enter "MyDurableFunctionsOrchestrator" as the name.
    8. Click Create.
    9. Wait for the function to appear.
  3. Challenge

    Add a Durable Activity Function to the Function App

    Now create the Durable Functions activity function:

    1. Click the Functions menu item in the navigation tree on the left of the page.
    2. Click New function near the top center of the page.
    3. From the list of trigger types, click Durable Functions activity.
    4. In the New Function panel the appears on the right of the page, enter "Hello" as the name.
    5. Click Create.
    6. Wait for the function to appear.
  4. Challenge

    Create a Durable Functions HTTP Starter Function in the Function App

    Now create the Durable Functions HTTP starter:

    1. Click the Functions menu item in the navigation tree on the left of the page.
    2. Click New function near the top center of the page.
    3. From the list of trigger types, click Durable Functions HTTP starter.
    4. In the New Function panel the appears on the right of the page, enter "MyDurableFunctionsHttpStart" as the name.
    5. Click Create.
    6. Wait for the function to appear.

    Now change the source code of the function to the following, which removes passing data from the request to the orchestrator function:

    #r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
    #r "Newtonsoft.Json"
    
    using System.Net;
    using Microsoft.Azure.WebJobs.Extensions.DurableTask;
    
    public static async Task<HttpResponseMessage> Run(
        HttpRequestMessage req,
        IDurableOrchestrationClient starter,
        string functionName,
        ILogger log)
    {
        // Function input comes from the request content.
        //dynamic eventData = await req.Content.ReadAsAsync<object>();
    
        // Pass the function name as part of the route 
        string instanceId = await starter.StartNewAsync(functionName, null);
    
        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
    
        return starter.CreateCheckStatusResponse(req, instanceId);
    }
    

    Click Save above the code to save this new code.

  5. Challenge

    Run the Durable Function Starter and Get the Results with Azure CLI

    1. Get the URL of the Durable HTTP start function by clicking </> Get function URL above the MyDurableFunctionsHttpStart code and copy the URL to the clipboard.

    2. Open an Azure CloudShell by clicking the CloudShell icon at the top of the page (it looks like a rectangle with a command line prompt within it).

    3. When the Welcome to Azure Cloud Shell panel opens at the bottom of the browser, click PowerShell. Click Show advanced settings. Use the same location as your lab provided resource group. You can use the existing Storage account or a new Storage account. Under File share, select Create new. In the box provided under File share, enter "files" without the quotes. Click Create storage.

    The panel will become blue and the shell will take a moment to initialize.

    When the prompt is available, run the following commands one at a time:

    ```powershell
    $startUrl = "<url from the Durable HTTP starter function>"
    ```
    

    Make sure to replace <url from the Durable HTTP starter function> with the actual URL copied in a previous step. After you paste in the URL, replace the {functionName} with MyDurableFunctionsOrchestrator. Now start the orchestration:

    ```powershell
    $r = Invoke-WebRequest -Uri $startUrl
    ```
    

    Parse the content in the result of the orchestration invocation:

    ```powershell
    $response = ConvertFrom-Json $r.Content
    ```
    

    Now retrieve the status of the orchestration: powershell $s = Invoke-WebRequest -Uri $response.statusQueryGetUri

    Parse the content of the status:

    ```powershell
    $status = ConvertFrom-Json $s.Content
    ```
    

    And finally retrieve the output of the orchestration:

    ```powershell
    $status.output
    ```
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans