In this lab, we create and run an Azure Durable Function and retrieve the result of the orchestration via PowerShell.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Log In to the Azure Portal
Log in to the Azure Portal using the username and password supplied by the lab.
- Open a browser.
- Navigate to the provided Azure Portal URL.
- Use the supplied username and password to authenticate.
- 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:
- Open the navigation menu in the upper-left of the Portal.
- Click All resources. Wait for the all resources list to appear.
- 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.
- Click the Functions menu item in the navigation tree on the left of the page.
- Click New function near the top center of the page.
- From the list of trigger types, click Durable Functions orchestrator.
- In the New Function panel that appears on the right of the page, enter "MyDurableFunctionsOrchestrator" as the name.
- Click Create.
- Wait for the function to appear.
- Add a Durable Activity Function to the Function App
Now create the Durable Functions activity function:
- Click the Functions menu item in the navigation tree on the left of the page.
- Click New function near the top center of the page.
- From the list of trigger types, click Durable Functions activity.
- In the New Function panel the appears on the right of the page, enter "Hello" as the name.
- Click Create.
- Wait for the function to appear.
- Create a Durable Functions HTTP Starter Function in the Function App
Now create the Durable Functions HTTP starter:
- Click the Functions menu item in the navigation tree on the left of the page.
- Click New function near the top center of the page.
- From the list of trigger types, click Durable Functions HTTP starter.
- In the New Function panel the appears on the right of the page, enter "MyDurableFunctionsHttpStart" as the name.
- Click Create.
- 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.
- Run the Durable Function Starter and Get the Results with Azure CLI
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.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).
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:
$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}
withMyDurableFunctionsOrchestrator
. Now start the orchestration:$r = Invoke-WebRequest -Uri $startUrl
Parse the content in the result of the orchestration invocation:
$response = ConvertFrom-Json $r.Content
Now retrieve the status of the orchestration:
$s = Invoke-WebRequest -Uri $response.statusQueryGetUri
Parse the content of the status:
$status = ConvertFrom-Json $s.Content
And finally retrieve the output of the orchestration:
$status.output