One can use app settings AzureWebJobs.<FUNCTION_NAME>.Disabled to disable individual Functions in an Azure Function. However, that of course requires that you know all the Function names.
Is there a way to disable all Functions in a similar way? (and no, just Stopping the function app is not an option).
In Local Azure Function Project, we can add the disabled attribute for the multiple functions we need to disable:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobs.BlobTriggerFunction.Disabled": true,
"AzureWebJobs.SingleTonTimerFunction.Disabled": true
}
}
As you're adding the custom attribute using C# class library in every function code like [Disable("FUNCTION_DISABLED")] which is also considerable but using application settings is recommended as specified in this MS Doc.
I have 3 different functions in which 2 are disabled using the above code.
One of the similar issues is in open state in GitHub regarding disabling all the functions at a time is a feature request and there are some temporary workarounds given which is possible using App Settings in the Portal Azure Function Configuration Menu but that is regarding to specific slot.
Related
In my local.settings I have nested settings like this
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"Email:Email": "test",
"Email:Password": "*******",
},
}
I am reading the values like this
config.GetValue<string>("Email:Email")
But when I am adding azure settings in azure function app (after deploying) I cannot add : into the name. Any suggestions for it?
One of the workaround you can follow,
When we are creating azure function in local and deploy to azure our localsettings.json file not upload .We need to update them manually by adding it on portal.
In localsettings.json file you have used : which is accepted by local environment. But When deploying we need to use __ instead.
Followed by this MICROSOFT DOCUMENTATION:-
The app setting name like ApplicationInsights:InstrumentationKey
needs to be configured in App Service as
ApplicationInsights__InstrumentationKey for the key name. In other
words, any : should be replaced by __ (double underscore).
Likewise you can set something like below e.g;
"Email__Email": "test",
"Email__Password": "*******",
For more information please refer this SO THREAD| azure application settings - how to add nested item & Nested object from local.settings.json in Azure function v3 settings .
How Can I publish my Azure Function's local.settings.json?
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"CosmoDbAuthKey": "***********************************",
"CosmoDbEndpoint": "https://**************************:443/",
"CosmosDbId": "***Notifications"
}
}
This answer is not condoning the practice of publishing the local.settings.json file, since it is intended to be used for local development and debugging only. Others have already emphasized that, but they are apparently mistaken that there is "no way to publish". There is indeed a method to publish it and it's specified in Microsoft's online docs:
By default, these settings are not migrated automatically when the project is published to Azure. Use the --publish-local-settings switch when you publish to make sure these settings are added to the function app in Azure. Note that values in ConnectionStrings are never published.
You cannot publish local.settings.json file to Azure. This file is for local development only.
To add settings for your deployed function:
Go to https://portal.azure.com
Navigate to your function app
In the left hand side menu, look for Settings
Select Configuration
The default loaded tab should be Application Settings
Select New application setting
Add Name and Value. Name should be the same as your local.setting.json entry i.e. CosmosDbId. Value may change depending on your environment.
You cannot publish local.settings.json, what you need to do is to add them under the "Application settings" tab of the published function app in the Azure Portal
How do I setup and configure an IoTHubTrigger correctly to trigger an Azure Function (C#) for my IoTHub messages? Where and how do I plug in my IoTHub's connection string?
Steps using Visual Studio 2017:
First make sure you have the latest version of the Azure Functions and Web Jobs Tools
Go to File->New->Project->Azure Functions and select "IoT Hub Trigger"
Select Functions V1 or V2 (learn about there differences here). And enter an arbitrary name that will serve as key for your connection string configuration.
Open local.settings.json and enter a key/value pair for your connection string:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"ConnectionString": "<your connection string>"
}
}
IMPORTANT
If using Functions V1, use your IoTHub connection string obtained in the portal from here:
If using Functions V2, use your IoTHub's EventHub compatible endpoint obtained in the portal from here:
Now set a breakpoint in your function and hit F5. You will see your messages flowing from IoTHub to your Azure Function (assuming you have devices or simulators connected that are sending data)
Steps using the Azure Portal
Create a new Function App resource and select the EventHub Trigger template
Hit "New" for EventHub Connection and select IotHub and your desired hub
Edit and save your function code - you are now up and running!
Switch to "Monitor" see your events flowing in
More options to create IoTHub Trigger Azure Functions
a) Using VS Code with the Azure Functions Extension
b) From the command line using Azure Functions Core Tools
I also needed to install a NuGet package Microsoft.Azure.WebJobs.Extensions.EventHubs
I would like to add, if you want to publish the function on Azure, you must add the connectionstring for the portal side
Updating the thread for cloud deployment issue. If you don't find an option to pass the connection string through the publish pop up window in Visual Studio 2022, you can provide the configuration from the Azure portal UI.
Navigate to the Azure function resource on the Azure portal and click on the Configuration under thh Settings section. Click the New Application Setting button on top and add in the connection string parameter name (same as the value set to Connection in the Azure function declaration) and provide the event hub end point connection string as value.
I've created an AzureWebApp running a docker image. The app starts, but it does not appear to be getting a connection string. I've defined the connection string as an AppSetting but I am not seeing that setting passed as an environment variable.
Should I expect to see my AppSetting on the container output? Something like
docker run -e CONNSTR=FOO
The docs imply that it should just be passed automatically, but I feel like I'm missing something.
Thanks
Joe
Turns out it was working all along. I had a legit issue with authenticating against the db. I needed some logging in the service to verify that it was getting the right connection string.
It appears that the app settings are passed to the container implicitly without showing up in the logs as an -e param.
I run into a similar issues when deploying an .NET Core 2 Azure Function, which was reading settings and connection strings using System.Configuration.ConfigurationManager. The root cause in my case was that ASP.NET Core introduced a new configuration API.
Find more details at https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.0&tabs=basicconfiguration.
Assuming you're deploying an ASP.NET Core application deployed into Web Apps for Containers, you may be running into a similar issue. Please try to the following:
a) Initialize the configuration as follows:
using Microsoft.Extensions.Configuration;
...
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("local.settings.json")
.AddEnvironmentVariables()
.Build();
b) Read connection strings as follows:
configuration.GetConnectionString("StorageAccountConnectionString");
c) Read settings as follows:
configuration["ContainerName"];
Here is a sample configuration file for my Azure Function:
{
"IsEncrypted": true,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"ContainerName": "container"
},
"Host": {
"LocalHttpPort": 7071
},
"ConnectionStrings": {
"StorageAccountConnectionString": "UseDevelopmentStorage=true"
}
}
I'm using the apiHubFileTrigger with the OneDrive for business connector(onedriveforbusiness_ONEDRIVEFORBUSINESS).
{
"bindings": [
{
"type": "apiHubFileTrigger",
"name": "myFile",
"direction": "in",
"path": "/InputFile/{file}",
"connection": "onedriveforbusiness_ONEDRIVEFORBUSINESS"
}
],
"disabled": false
}
It's working well when I am monitoring the script inside the azure portal. But soon as I close the editor and wait for some time, the function is not be triggered on new files copied to onedrive for business. There is no error or anything in invocation logs. (No invocation at all)
The function is written in C#. The function will use the input file and perform some operations based on file. Since its working when I am inside the portal and monitoring it, the issue is not related to code.
I'm running the consumption plan so the problem has nothing to do with "always on"
To summarize the discussion in the comments, there is an outstanding bug with Consumption Plan functions where triggers sometimes get out of sync and don't fire unless the portal is open if they are published in certain ways (details here: https://github.com/Azure/Azure-Functions/issues/210)
In those cases, hitting the "refresh" button next to the function app in the portal will sync the trigger.
In this case, there was an issue with storage account connection string parsing. The workaround is to switch to an App Service Plan function (making sure that "Always On" is "On").