In Azure Functions, where do we put settings we want to put on Azure? - azure

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?

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.
Further more information, you could refer to this tutorial: Publish to Azure.

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

Related

How to configure appsettings on a auto-generated preview environment

How can I change the appsettings on the preview environemnts that are generated by the Azure Static Web Apps CI/CD Github Action for each pull request?
I can go to the portal, navigate to the generated environment and change its appsettings. Doing this manually for each new pull request is error prone and will become tedious really fast.
I couldn't find any reference to this in the Build Configuration For Azure Static Webapps docs so I'm assuming it can't be configured that way.
I also couldn't find any reference to SWA environments in the CLI docs.
I looked into deployment environments but it looks like this is some other kind of deployment environment as it keeps mentioning devcenter.
In Azure Portal, While Creating Static Web App, after providing the GitHub Repo and Branch details, we will get an option to preview the Workflow file.
I can go to the portal, navigate to the generated environment and change its appsettings
Yes, In Configuration Section we have an option to add the App settings. But it is a manual work, which is not advised to follow.
Once we click on Review + create and create the Static Web App, a new folder with name .github/workflows will be created in the GitHub Repository.
It contains the same workflow file (preview file), which we saw while creating the Static WebApp in Azure Portal.
We can edit the Workflow manually.
To update the appsettings/configurations in the workflow, we can specify the steps in the existing workflow file.
We can use either Powershell/Azure CLI commands to update the Appsettings.
az staticwebapp appsettings set --name YourStaticWebAppname --setting-names "message=HelloEveryOne"
***Sample code for Updating App settings: ***
Before Build and deploystep in Workflow, add the below steps.
- name: Build And Deploy
- run : Your Update appsettings Script
To edit the Workflow file, click on the .github/workflow => .yml file
References taken from MSDoc 1 and 2.
Update
As per the discussion in GitHub, adding appsettings to the preview environment is not currently supported in the default Azure Static Web Apps CI/CD.
Setting appsettings on a specific environment is not currently supported in the Azure Static Web apps CI/CD nor by the Azure CLI.
There is a discussion in GitHub about it.

Azure devops add single configuration application setting to function app using YAML without modifying existing configuration

I need to add single application setting without modifying existing configuration for function app, I found this question Set App Service application setting from Azure DevOps yaml but looking at the solution (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-app-service-settings?view=azure-devops) it looks like this will overwrite settings rather than adding new setting, I would like to just pass key and value to be added rather than writing whole appconfig.
Soulution for me was to use command from https://learn.microsoft.com/en-us/cli/azure/webapp/config/appsettings?view=azure-cli-latest#az-webapp-config-appsettings-set
az webapp config appsettings set -g GRPNAME -n APPNAME --settings dummy1=dummy1value

Can't find app with name error while publish the azure function

I tried to create an azure function using following link in Ubuntu system(16.04).
[azure function][2]
Deployment using arm template and create a local azure function using vs code.
Folder contains following files
LocalFunctionProj.csproj, HttpExample.cs, host.json, local.settings.json
azure function is created successfully in portal after deployment.But when i tried to publish the local azure function ,it shows an error Can't find app with name "HttpExample" while using following command
func azure functionapp publish HttpExample
Is anything wrong in my step.
Also i tried this command after 30 mnt when function created in portal
screen shot
I had a similar issue when I followed a tutorial about Azure Functions Core Tools from Microsoft Learning.
In my case, I had the error Can't find app with name X, because I had a wrong subscription set in my local Azure CLI. The command from below changes subscription for the one that is created with "Microsoft Learning Sandbox". Note that, in your case, the name of the subscription can be different.
az account set --subscription "Concierge Subscription"
If it's not the issue, your question suggests that your function app name should be HttpExample. You need to ensure beforehand that there's a function app with such a name in the subscription you are logged into with Azure CLI.
Moreover, there is a ProvisioningState: Failed in the screenshot, which could also be an issue.
If you want to publish the local app into azure ,you must create the functional app before in azure portal.Also the name of the azure function is portal should be same as the local azure app.otherwise you can't publish the app.

How do I get into the folder of a Web App in Azure

Recently I am trying to use:
func azure functionapp publish WebAppName --publish-local-settings -i
to publish local.settings.json to a web app (actually an Azure function) but I get this error message:
Unable to find project root. Expecting to find one of host.json in project root.
I have logged in to Azure with az login but it looks like I need to get into the folder where I have deployed the Azure function where all those json files are.
A little background, we are using Octopus Deploy to deploy to an Azure function. After the deployment, we want to add a step so that the local.setting.json will be used to populate app settings.
So how do we change the current folder to be in the Azure function root where all those json files are?
Thanks a lot in advance!
You need to go to your local function project folder to run the command, for example, my function project is under MyFunctionProj folder.
Execute the command
func azure functionapp publish tonyfunc --publish-local-settings -i --publish-settings-only
By the way, if you just want to update the settings, you need add --publish-settings-only parameter.
Reference:
Core Tools development

Azure Function how to move appsettings from local to server and vice versa

I m a little new to Azure.
Issue is I m developing Azure Functions and some times I have to work locally (code/ test etc) and other times on Azure. Every time I switch I have to compare and change app settings manually.
Is there a way I can avoid it ? Something where if I run locally I may get latest from server without manual and when I go to server Azure may be aware of my changes ?
Thanks
Yes, use the Azure Functions Core Tools —
Usage: func azure functionapp <action> [-/--options]
fetch-app-settings Retrieve App Settings from your Azure-hosted
Function App and store locally Aliases:
fetch-app-settings, fetch
and
Usage: func azure functionapp <action> [-/--options]
publish Publish the current directory contents to an
Azure Function App. Locally deleted files
are not removed from destination.
<FunctionAppName> Function App name
--publish-local-settings [-i] Updates App Settings for the
function app in Azure during deployment.
--publish-settings-only [-o] Only publish settings and skip the
content. Default is prompt.
--overwrite-settings [-y] Only to be used in conjunction with -i or -o.
Overwrites AppSettings in Azure with local
value if different. Default is prompt.
There's also encryption for the local file if you feel a little adventurous —
run func settings to get usage.

Resources