Azure Functions is a serverless computing platform in Azure. You can use Functions to support extra scenarios in Azure DevTest Labs. When you use Functions in a solution with DevTest Labs, you can augment the existing service features with your own custom code.
This article shows how to extend DevTest Labs built-in functionality to provide a top-level summary of virtual machines (VMs) in a lab. Here are some other scenarios you can support by extending DevTest Labs with Functions:
The following sections provide step-by-step instructions for setting up the Azure Resources needed to update the Internal support page in DevTest Labs. This walkthrough provides one example for how to extend DevTest Labs. You can use this pattern for other scenarios.
Explore sample scenario
The sample walkthrough in this article extends DevTest Labs by using Functions to support the following features:
Provide a top-level summary of all VMs in a lab
Enable lab users to see virtual machine (VM) details, including operating system, owner, and applied artifacts
UpdateInternalSupportPage: Queries DevTest Labs and updates the internal support page directly with details about the lab VMs.
ApplyWindowsUpdateArtifact: Applies the Windows update artifact to all VMs in the lab, as needed.
The following diagram demonstrates the overall flow of function behavior in the scenario:
When the user browses to the Internal support page in DevTest Labs, they see a prepopulated page with information about lab VMs, lab owners, and support contacts.
When the user selects the Select here to refresh option, the page calls the Azure function UpdateInternalSupportPage. This function queries DevTest Labs for information and then refreshes the Internal support page with the latest information.
When a VM doesn't have a recent Windows update artifact, the user can select the *Run Windows update option for the VM. The page calls the Azure Function ApplyWindowsUpdateArtifact. This function checks whether the VM is running, and if so, applies the Windows Update artifact directly.
Prerequisites
To work with the sample in this walkthrough, you need a service principal that has permission to the subscription that contains the lab. The service principal must use password-based authentication. If you already have a service principal that you can use in this walkthrough, you can continue to the next section.
After you publish the Function app, you need to get URLs for the functions from the Azure portal:
In the Azure portal, go to the Function App page, and select the Function app that you created in Visual Studio.
On the Overview page for the Function app, locate the Functions section and select one of the functions: UpdateInternalSupportPage or ApplyWindowsUpdateArtifact:
On the Code + Test page for the Azure function, select Get function URL.
On the Get Function URL pane, use the Copy action to copy the desired URL to your clipboard:
Save the copied URL for later use.
Repeat these steps for the other Azure function.
Update application settings
In addition to the URL for each function, you also need to update information about the service principal, including the application ID, key, and tenant ID.
Follow these steps to update the required application settings in Visual Studio:
In Visual Studio, return to the Publish page for the AzureFunctions project.
In the Hosting section, select More actions (...), and then select Manage Azure App Service settings:
On the Application settings dialog, update the Remote value for the following settings:
AzureFunctionUrl_ApplyUpdates
AzureFunctionUrl_UpdateSupportPage
WindowsUpdateAllowedDays (default to 7)
ServicePrincipal_AppId
ServicePrincipal_Key
ServicePrincipal_Tenant
Select OK.
Test Azure function
The last step is to test the Azure function:
In the Azure portal, go to the Function App page, and select the Function app that you created in Visual Studio.
On the Overview page for the Function app, locate the Functions section and select the UpdateInternalSupportPage function.
On the Code + Test page for the Azure function, select Test / Run.
On the Test / Run pane, enter values for the route properties: LABNAME, RESOURCEGROUPNAME, and SUBSCRIPTIONID:
Select Run to execute the function. The function test updates the internal support page of the specified lab. It also includes an option for users to directly call the function next time.
In this learning path, discover Azure Functions that create event-driven, compute-on-demand systems using server-side logic to build serverless architectures.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.