This is a follow up question to this question:
appsettings.json and azure function by timer
I want to have dynamic settings which I can change without redeploying the Azure function.
The linked question referrers to a short article: https://medium.com/awesome-azure/azure-reading-application-settings-in-azure-functions-asp-net-core-1dea56cf67cf
I understood from the article how to handle local settings meant for debugging locally using the local.settings.json file. What I didn't understand is what I need to do to add settings when running in the cloud and how exactly to read them.
So my questions are:
How do I add settings to read when running in Azure (not sure from the article what is this "Application Settings" in the picture there)?
Will using
var value = Environment.GetEnvironmentVariable("your_key_here");
work for both local environment and when running in Azure?How can I change one of the setting from the outside without having to redeploy the function?
CodePudding user response:
In code, read the settings from environment variables. Then...
- For local development, you can add settings in the local.settings.json file.
- In Azure, add settings with the same name in Application settings
- Application settings override settings.json
App settings in a function app contain configuration options that affect all functions for that function app. When you run locally, these settings are accessed as local environment variables.
and
The function app settings values can also be read in your code as environment variables.
- By adding them in the Application Settings for the Function App
- Yes.
- Change it in Application Settings (it will restart)
For an even more centralized way of working with settings and not restarting your application (if you don't want it to), have a look at App Configuration.