Home > other >  Using appsettings in Azure function
Using appsettings in Azure function

Time:04-06

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:

  1. 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)?

  2. Will using var value = Environment.GetEnvironmentVariable("your_key_here"); work for both local environment and when running in Azure?

  3. 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.

See Use application settings.

  1. By adding them in the Application Settings for the Function App
  2. Yes.
  3. 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.

  • Related