Updating Azure Functions runtime

August 11th 2023 Azure .NET

I was recently involved in updating a bunch of .NET projects deployed to Azure from older versions to .NET 6. Among them, there was also an Azure Function app. To my surprise, unlike Azure Web App services, not everything could be reconfigured through Azure Portal.

Updating a .NET Azure Function from an older .NET runtime to .NET 6 also involves changing Azure Function runtime from 3 to 4. This has to be done both in the project file and in the Azure resource the application is deployed to. When looking at the Azure Function app in the Azure portal, the runtime configuration can be found on the Function runtime settings tab of the Settings > Configuration page.

Azure Function runtime version in Azure Portal

However, the dropdown is read-only, and if you have an existing Azure Function app with an old runtime version, you can't change it here. Instead, you need to use Azure CLI. If you already have Azure CLI installed and authenticated with your Azure account, you only need to run the following two commands to reconfigure the Azure Function app runtime for .NET 6:

az functionapp config appsettings set --settings FUNCTIONS_EXTENSION_VERSION=~4 -g <RESOURCE_GROUP_NAME> -n <APP_NAME>
az functionapp config set --net-framework-version v6.0 -g <RESOURCE_GROUP_NAME> -n <APP_NAME>

In the commands above, replace <RESOURCE_GROUP_NAME> and <APP_NAME> with your resource group and resource name.

In my case, the problem was that I didn't have the permission to perform this change:

(AuthorizationFailed) The client '...' with object id '...' does not have authorization to perform action 'Microsoft.Web/sites/config/list/action' over scope '/subscriptions/.../resourceGroups/.../providers/Microsoft.Web/sites/.../config/appsettings' or the scope is invalid. If access was recently granted, please refresh your credentials.

That's not uncommon with large clients, but it also means that you need someone with sufficient permissions to execute these commands, and that someone needs to have Azure CLI set up to be able to do it. Fortunately, these commands also work in Azure Cloud Shell which is much easier to set up:

  • Open Azure Cloud Shell by clicking the icon on the right side of the top toolbar: Azure Cloud Shell icon in Azure Portal toolbar
  • If you're running it for the first time, you need to create an Azure Storage account by selecting a subscription and confirming the action: Creating Azure Cloud Shell storage account

  • Once the Azure Storage account is created, a Bash terminal opens. Before you can execute the above commands, you need to select your subscription and register it with Azure Cloud Shell to get access to the resources (you can find the <SUBSCRIPTION_ID> value on the Subscriptions page of Azure Portal):

az account set --subscription <SUBSCRIPTION_ID>
az provider register --namespace Microsoft.CloudShell

With that set up, you can now execute the commands at the beginning of this post to reconfigure an Azure Function app for .NET 6.

When working with large clients, you might not have full permissions in their Azure account, so they will sometimes have to do some reconfiguration themselves following your instructions. Most of the changes can be done through the Azure Portal graphical user interface, which isn't too difficult even for less technically savvy people. When Azure CLI needs to be used, setting up Azure Cloud Shell can be an easier alternative to installing the Azure CLI locally. That's the approach I used to get an Azure Function app reconfigured for .NET 6.

Get notified when a new blog post is published (usually every Friday):

Copyright
Creative Commons License