JVermeulen
JVermeulen

Reputation: 225

Use Cloud App settings in Azure Functions

In App Web I can set my app settings in the cloud settings and use configurationmanager.appsetting to retrieve them.

How can I set my appsettings with Azure functions, do I need to use local config file again?

Upvotes: 3

Views: 3121

Answers (2)

Sander van den Hoven
Sander van den Hoven

Reputation: 652

It is not required to use local config files again.

In your Function App, you can still access the webapp that hosts your function app. If you go to the setting In the settings you can still define the application settings and set an appsetting.

In your code in the Azure Portal to your function app and the to the Function App Settings you can go to the App Service Settings. You will be redirected to the settings of the web app where you can set the appsettings as a normal webapp.

In the code you can access the configurationmanager.appsettings[] like a normal .Net Application.

Sander

Upvotes: 1

Harris K
Harris K

Reputation: 111

To add into the Sander's answer, in order to get the Function to read the appsettings locally we need to put the Key and Value App Settings inside the file local.settings.json (put all settings just as we would on Azure), so the content should look similar to this:

{
 "IsEncrypted": false,
  "Values": 
   {
    "AzureWebJobsStorage": "",
    "AzureWebJobsDashboard": "",
    "FUNCTIONS_EXTENSION_VERSION": "~1",
    "NameOfTheKey": "TheValue"
   }
}

When you run the Function App locally it should read the app settings from the file above.

PS. You can find the local.settings.json file in the root directory of your project. Some of you might find the file named as appsettings.json depending on which Azure CLI Version you are using, it should still work either way.

Upvotes: 2

Related Questions