Upgraded Azure Function cannot test from the portal - azure

We had a Azure Function with Timer Trigger which was develop using function version 3.0 and .NET 3.1. This function is running on Windows App Service Plan on Azure. So, I have upgraded it to function version 4.0 and .NET 6.0 using below steps:
Upgrade your local project
The following changes are required in the .csproj XML project file:
Change the value of PropertyGroup.TargetFramework to net6.0.
Change the value of PropertyGroup.AzureFunctionsVersion to v4.
Replace the existing ItemGroup.PackageReference list with the following ItemGroup:
Image
After you make these changes, your updated project should look like the following example:
Image
Upgrade the local.settings.json file
Image
Run the function app locally and verify the functionality.
Upgrade your function app in Azure
Run below command to set the FUNCTIONS_EXTENSION_VERSION application setting to ~4 on your function app in Azure.
az functionapp config appsettings set --settings FUNCTIONS_EXTENSION_VERSION=~4 -g <RESOURCE_GROUP_NAME> -n <APP_NAME>
Change the .NET version of the function app. If you're function app is hosted on Windows, run below command.
az functionapp config set --net-framework-version v6.0 -g <RESOURCE_GROUP_NAME> -n <APP_NAME>
However, I cannot test or see the function.json file from Azure Portal.

I have taken the .NET 3.1 Azure Function Project with Timer Trigger in the VS 2022 IDE:
Published the .NET Core 3.1 Azure Functions Project to Azure Function App in the Azure Portal and then changed the FUNCTIONS_EXTENSION_VERSION to 4 using Azure CLI Command by following this MS Doc:
Running locally after migration to V4-.NET 6:
Then, deployed the migrated project to the Azure Function App and tested as shown below:

I was able to find the reason for the issue by running "Diagnose and solve problems" from Azure portal.
The issue was related to the function name. My function name length was more than 32 characters long. By default, the Host ID is auto-generated from the Function App name, by taking the first 32 characters. If you have multiple Function Apps sharing a single storage account and they're each using the same Host ID (generated or explicit), that can result in a Host ID collision. For example, if you have multiple apps with names longer than 32 characters their computed IDs may be the same. Consider two Function Apps with names myfunctionappwithareallylongname-eastus-production and
myfunctionappwithareallylongname-westus-production
that are sharing the same storage account. The first 32 characters of these names are the same, resulting in the same Host ID myfunctionappwithareallylongname being generated for each(Please refer https://github.com/Azure/azure-functions-host/wiki/Host-IDs#host-id-collisions for more information).
So, to solve the issue, I just rename the function name on Azure.

Related

Durable function template missing from function templates list

I've created a web app and first durable function in it. Ran npm install durable-functions at the root of the directory of the app. But trying to create an orchestrator/second function app I see this warning in my portal. I do not see the durable function template in the list of azure function templates to create. How do I get this option back? Please help. Looks like I don't have the whole collection of extensions bundle. Where should this be installed?
This is what my host.config looks like. The extension bundle supported was 1* to 2.0 after running npm install durable-functions but I've updated it to 2* to 3.0 after reading https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-register
This is my package.json file
I recreated a new storage account and added application strings to my function app AzureWebJobsStorage and AzureWebJobsDashboard with value from the connection string for the new storage account. Restarted my function app.

Azure function error: app does not support remote build as it was created before August 1st, 2019

I am trying to deploy my azure function with VS code using func azure functionapp publish nhtsa --build remote and I am getting below error.
Remote build is a new feature added to function apps.
Your function app does not support remote build as it was created before August 1st, 2019.
Please use '--build local' or '--build-native-deps'.
For more information, please visit https://aka.ms/remotebuild
I thought it's because of the storage account access -tier and access level, so I change my storage account tier to cool and container access to public, and I deploy the function again, and I'm still getting the error.
Any idea how I can resolve this issue.
Thanks
As the error specified, it is not supported for function app created before August 1, 2019 (see documentation):
If you're having issues with remote build, it might be because your app was created before the feature was made available (August 1, 2019). Try creating a new function app, or running az functionapp update -g <RESOURCE_GROUP_NAME> -n <APP_NAME> to update your function app. This command might take two tries to succeed.
I had the same issue the solution was to fix the "defaultAction"
It should be "Allow"

Can't find app with name error while publish the azure function

I tried to create an azure function using following link in Ubuntu system(16.04).
[azure function][2]
Deployment using arm template and create a local azure function using vs code.
Folder contains following files
LocalFunctionProj.csproj, HttpExample.cs, host.json, local.settings.json
azure function is created successfully in portal after deployment.But when i tried to publish the local azure function ,it shows an error Can't find app with name "HttpExample" while using following command
func azure functionapp publish HttpExample
Is anything wrong in my step.
Also i tried this command after 30 mnt when function created in portal
screen shot
I had a similar issue when I followed a tutorial about Azure Functions Core Tools from Microsoft Learning.
In my case, I had the error Can't find app with name X, because I had a wrong subscription set in my local Azure CLI. The command from below changes subscription for the one that is created with "Microsoft Learning Sandbox". Note that, in your case, the name of the subscription can be different.
az account set --subscription "Concierge Subscription"
If it's not the issue, your question suggests that your function app name should be HttpExample. You need to ensure beforehand that there's a function app with such a name in the subscription you are logged into with Azure CLI.
Moreover, there is a ProvisioningState: Failed in the screenshot, which could also be an issue.
If you want to publish the local app into azure ,you must create the functional app before in azure portal.Also the name of the azure function is portal should be same as the local azure app.otherwise you can't publish the app.

In Azure Functions, where do we put settings we want to put on Azure?

So just started playing with Azure Functions, I have a new project with some appsettings in the local.settings.json file.
So this works on my local, but obviously when I deploy to Azure Functions, local.settings.json file isn't used.
Where are we supposed to specify our settings for an Azure Function?
Is there a azure.settings.json file? Or some sort of way to deploy an settings file during the deployment?
If you want to add settings, you could use the way provided by Matt, and if you want to deploy the Function to Azure with the settings in the local.settings.json, there is another way to implement it.
Install the Azure Functions Core Tools on the local, publish the Function with -publish-local-settings -i and if you are using the version 2 the --publish-settings-only -o could only publish settings and skip the content.
The below pic is a sample, you could find it will prompt to overwrite value in azure if setting is different between azure and local.settings.json.
Further more information, you could refer to this tutorial: Publish to Azure.
Just like an Azure App Service, and Azure Function has an Application Settings tab where you can configure these through the Azure Portal. To access these you go to: Your function app > Overview > Configured Features> Configuration, you can then add the settings that you need under the Application Settings tab.
Alternatively, if you would prefer configuring these through a CLI then that option is also available. The main documentation is here.
Edit
For a solution as part of your CI/CD you have two options (examples will use Azure DevOps and perform the action in the CD step):
PowerShell Task. You could add a Powershell (or any type of script that will talk to the Azure CLI for functions) script as part of your CD step. This post goes through the process step by step, the bit you are probably interested in is under "Deploying with Azure DevOps Release Pipeline". Essentially it is building up a collection of your appsetting keys and their values, then a call to Set-AzureRmWebApp the and pass in the collection to the -AppSettings flag as per these docs
Azure CLI task. Same as above but you could use the Azure CLI task along with the Inline script option to call the az functionapp config appsettings set command docs here. The --settings flag takes:
Space-separated app settings in a format of =.
So
az functionapp config appsettings set --name MyFunctionApp --resource-group MyResourceGroup --settings "settings1Key=settings1Value settings2Key=settings2value"
The Azure Functions for .NET template for CI (Build) and Deploy a function app to Azure Functions template for CD (Release) inside Azure DevOps will come in handy.

Azure Function how to move appsettings from local to server and vice versa

I m a little new to Azure.
Issue is I m developing Azure Functions and some times I have to work locally (code/ test etc) and other times on Azure. Every time I switch I have to compare and change app settings manually.
Is there a way I can avoid it ? Something where if I run locally I may get latest from server without manual and when I go to server Azure may be aware of my changes ?
Thanks
Yes, use the Azure Functions Core Tools —
Usage: func azure functionapp <action> [-/--options]
fetch-app-settings Retrieve App Settings from your Azure-hosted
Function App and store locally Aliases:
fetch-app-settings, fetch
and
Usage: func azure functionapp <action> [-/--options]
publish Publish the current directory contents to an
Azure Function App. Locally deleted files
are not removed from destination.
<FunctionAppName> Function App name
--publish-local-settings [-i] Updates App Settings for the
function app in Azure during deployment.
--publish-settings-only [-o] Only publish settings and skip the
content. Default is prompt.
--overwrite-settings [-y] Only to be used in conjunction with -i or -o.
Overwrites AppSettings in Azure with local
value if different. Default is prompt.
There's also encryption for the local file if you feel a little adventurous —
run func settings to get usage.

Resources