1
votes

So just started playing with Azure Functions, I have a new project with some appsettings in the local.settings.json file.

So this works on my local, but obviously when I deploy to Azure Functions, local.settings.json file isn't used.

Where are we supposed to specify our settings for an Azure Function?

Is there a azure.settings.json file? Or some sort of way to deploy an settings file during the deployment?

2

2 Answers

3
votes

If you want to add settings, you could use the way provided by Matt, and if you want to deploy the Function to Azure with the settings in the local.settings.json, there is another way to implement it.

Install the Azure Functions Core Tools on the local, publish the Function with -publish-local-settings -i and if you are using the version 2 the --publish-settings-only -o could only publish settings and skip the content.

The below pic is a sample, you could find it will prompt to overwrite value in azure if setting is different between azure and local.settings.json.

enter image description here

Further more information, you could refer to this tutorial: Publish to Azure.

2
votes

Just like an Azure App Service, and Azure Function has an Application Settings tab where you can configure these through the Azure Portal. To access these you go to: Your function app > Overview > Configured Features> Configuration, you can then add the settings that you need under the Application Settings tab.

https://i.imgur.com/u817Myj.png

Alternatively, if you would prefer configuring these through a CLI then that option is also available. The main documentation is here.


Edit

For a solution as part of your CI/CD you have two options (examples will use Azure DevOps and perform the action in the CD step):

  • PowerShell Task. You could add a Powershell (or any type of script that will talk to the Azure CLI for functions) script as part of your CD step. This post goes through the process step by step, the bit you are probably interested in is under "Deploying with Azure DevOps Release Pipeline". Essentially it is building up a collection of your appsetting keys and their values, then a call to Set-AzureRmWebApp the and pass in the collection to the -AppSettings flag as per these docs
  • Azure CLI task. Same as above but you could use the Azure CLI task along with the Inline script option to call the az functionapp config appsettings set command docs here. The --settings flag takes:

Space-separated app settings in a format of =.

So

az functionapp config appsettings set --name MyFunctionApp --resource-group MyResourceGroup --settings "settings1Key=settings1Value settings2Key=settings2value"

The Azure Functions for .NET template for CI (Build) and Deploy a function app to Azure Functions template for CD (Release) inside Azure DevOps will come in handy.