Last time we visited Azure Functions, I did a brief introduction of Azure Functions 3.0 that now supports Node 12. The function app runtime you select gives you different options when it comes to platform versions. Go and check out that post if you want to know more.
I have created a Function App and a Function with version 2.x. And today we are going to have a look at the different options when it comes to migrating from 2.x to 3.x. There’s not a lot of steps. I will give you a few options and try to clarify a few things.
As I mentioned in the previous post, if there’s a function added to the function app we could only change the runtime between 2.x and 3.x. Changing to 1.x is only possible if there’s no function.
We could move into the Function app settings and from there just change from ~2 to ~3. This takes a few moments and then we have successfully changed the runtime.
This will change the Application settings to have runtime ~3 and Node version ~12. And this means that changing the application settings also forces a runtime change. We could go either path.
In the previous post, we had a look at how to use Azure CLI to get all app settings and even query for specific settings. Now we will look at how to change the settings. As mentioned earlier, this makes the same changes as if we would change the runtime in the portal.
Here we use the command az functionapp config appsettings set to set the runtime for the function app. we also use the name of the function app and the name of the resource-group.
az functionapp config appsettings set -n funcappsimon -g rgfuncappsimon -s FUNCTIONS_EXTENSION_VERSION=~3
Here we use the command az functionapp config appsettings set to set the Node versions for the function app. we also use the name of the function app and the name of the resource-group.
az functionapp config appsettings set -n funcappsimon -g rgfuncappsimon -s WEBSITE_NODE_DEFAULT_VERSION=~12
Using Azure Functions Extension we could just use the available application settings, right-click and edit the setting.
Many times we only need to make changes in Azure, if there are no breaking changes or we don’t need to deploy anything else.
Even though the migration is often smooth there are still some breaking changes: https://docs.microsoft.com/sv-se/azure/azure-functions/functions-versions#javascript
I’m primarily using the extension when it comes to creation, deployment and changing settings. This is not the first time I’m mentioning the extension. In an old post of mine, I’m walking you through the steps on how to generate a Function App and functions using the Azure Functions Extension for Visual Studio Code.
Nowadays you change the settings of your extension in VS Code when it comes to project language and runtime. If you look at the picture you can see that I have ~2 selected from before. I can now just change it to ~3 to match de default values of the Azure Portal and Azure CLI.
I used the extension to deploy the Function App to Azure as a 2.x. And if we have made our changes in Azure and changed the runtime to 3.x, and then try to deploy, the extension picks this up. You could still deploy, but it notices you have a local 2.x project and a 3.x in Azure.
So go into your code project, .vscode, and then in settings.json change the azureFunctions.projectRuntime to ~3.
Beware that changing the local project setting to ~3 and then deploying to an already deployed function app does NOT change the runtime in Azure.
My preferred way would be to use the Azure Functions Extension all the way. Remember to change the default version to ~3. And the approach for migration would be:
~3 in the settings.json. npm start and try the function locally in the emulator. Make sure it worksAzure Function Extension change the app settings of the function app to use runtime ~3 and node ~12.Now it’s deployed and hopefully working. And you are awesome!
