I have these entries in my local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "whateverstorageaccountconnectionstring",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
},
"BusinessUnitMapping": {
"Values": {
"Connections": "CON",
"Products": "PRD",
"Credit & Affordability": "CAA",
"Accounts Receivable": "ARC",
"Identity": "IDT"
}
}
}
I have this code to read the values in startup
services.Configure<BusinessUnitMapping>(options => configuration.GetSection("BusinessUnitMapping").Bind(options));
where BusinessUnitMapping is
public class BusinessUnitMapping
{
public Dictionary<string, string> Values { get; set; }
public BusinessUnitMapping()
{
Values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
}
when the I run the function app locally, it can read these settings into BusinessUnitMapping without any issue.
Advanced Edit for Application Settings in Azure Portal only allows simple Key Value pair as below
[
{
"name": "AzureWebJobsDashboard",
"value": "DefaultEndpointsProtocol=Somevalue",
"slotSetting": false
},
{
"name": "AzureWebJobsStorage",
"value": "DefaultEndpointsProtocol=Somevalue",
"slotSetting": false
},
...
]
-Alan-
Under Settings, choose Configuration. In the Function runtime settings tab, locate the Runtime version. Note the specific runtime version. In the example below, the version is set to ~4 .
AzureWebJobsStorage. The Azure Functions runtime uses this storage account connection string for normal operation. Some uses of this storage account include key management, timer trigger management, and Event Hubs checkpoints. The storage account must be a general-purpose one that supports blobs, queues, and tables.
- Is this a correct approach to store the complex app settings in Azure Function?
This is still an open question: see this github issue asking exactly this
- How do I get BusinessUnitMapping configured in Azure Portal for the Function App that I have deployed?
My current preferred approach is to use the options pattern with a delegate that uses GetEnvironmentVariable which will work both locally and in Azure. The downside is that you can't create complex types in the local settings file itself, but your object can be as complex as you like.
A simple example:
In local.settings.json:
{
...
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
...
"SomeSection:Setting1": "abc",
"SomeSection:Setting2": "xyz",
},
...
}
In your startup:
services.Configure<MySettingsPoco>(o =>
{
o.Setting1 = Environment.GetEnvironmentVariable("SomeSection:Setting1");
o.Setting2 = Environment.GetEnvironmentVariable("SomeSection:Setting2");
});
Then in Azure you can create these settings as follows:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With