This article:
https://www.visualstudio.com/en-us/docs/release/examples/azure/change-config-azure-webapps
discusses using the Powershell Set-AzureWebsite command to "change the appSettings and connectionStrings values in the Web.config file"
Is this applicable to Azure Functions?
Yes, they are based on the same platform, so this works identically. e.g. if you set an Azure App Setting called FOO, you will have an environment variable called FOO that you can consume in your Function logic.
Or if using C#, you can also write ConfigurationManager.AppSettings["FOO"].
Related
Is it possible to lookup the application name for an Azure app as it runs, i.e., get the information about that is displayed in the Azure portal? In the example below, I'd want something to tell me from within the application that I am running sitemap-prod-eastus.
I've been looking at the Azure Context object but not seeing what I need. There is an invocation ID, a name for the function, a directory - not the info in this window.
Maybe this can be done through Azure Application Insights?
I am working in Node JS.
I've not seen anything that would expose this to a function app. That said, there is one sort of workaround that you could do which would work - go to the Configuration blade for the function app, Application settings tab, and add a configuration key like function_name and set its value to the name of your app. Your app could then just read it out of configuration.
It's an extra step, but if you're doing it with something like ARM or Terraform, it's just another configuration entry with a variable you already declared to set up the app in the first place.
Answering my own question: Azure provides WEBSITE_SITE_NAME in the runtime environment that matches the name of the function app.
my project has 3 Service bus and 2 HTTP triggers. (5 functions)
How to deploy each function in a separate Azure function app?
The easiest way is to copy the code of the trigger you created before and create a new function app with a single trigger, then put the code into it(Deploy function app must be based on function app, and the function app should correspond to the project on local.).
The more complicated method is, first make sure the structure of your function app(this needs to check the language. function app has two types, one type is a scripting language and another type needs to be compiled.) For this, you can have a check of this official doc:
https://learn.microsoft.com/en-us/azure/azure-functions/supported-languages
Go to the language you are using and search the folder structure(your deployment structure should like the 'folder structure' in the doc. What needs to pay attention to is for the language like C# and java, you need to deploy the compiled files. Azure can't identify the source files.) Then you just need to imitate the structure and deploy based on this structure.
'Deploy' operation is just a upload operation, so you just needs to upload the files in specific structure, then azure can identify it.
Finally, you can use zip deploy to deploy your function app(Or to say deploy a project, a structure that azure can run must first run success on local.).
az webapp deployment source config-zip --resource-group <group-name> --name <app-name> --src clouddrive/<filename>.zip
(Above command is been used by some Integrated Development Environment, such as Visual Studio.)
I suggest you to use the first way, because it is simpler.
In Azure Devops Variable Groups you do something like:
FileRepo = 'FolderA'
LogFile = '$(FileRepo)/Log.txt'
Is this possible in Azure App Configuration?
*UPDATE:
When using the App Configration as an Azure Devops Task extenstion, $() references will work during pipelines.
No, this is not possible. Settings are flat and they do not support referencing to other settings values. You can try to do this programmatically, by replacing your tokens with real values, but there is nothing out of the box.
I have a lot of Azure Functions projects to deploy on Azure. I set build and pipeline for them. For example, this is one Release for an Azure Function.
Under Variables I defined all variables for the environments (one for dev, one for stage and one for production).
There is only one step for deploying the Azure Functions on Azure. I want to add/replace in the local.settings.json the right settings for an environment. I'm not be able to find how to configure that.
In other project, if I use Azure App Service Deploy, there is a section File Transforms & Variable Substitution Options.
How can I do the same in the release of an Azure Functions? What is the correct strategy or best practice?
Update and Solution
I thought it was much straightforward. I think this is the solution. In the App settings under Application and Configuration Settings, I have to specified each variable and its value using the ... in that line.
I can type or copy in this field. The syntax is
-variableName "$(variablename)"
I'm using quotes because if in the value there is any space (for example in the connection string you have Initial Catalog) DevOps raises an error. For array, I'm still using :.
Another way is to use File Transform task to substitute the variables in local.settings.json file with pipeline variables. See here for more information.
With File Transform task, you donot have to specify each variable and its value in App settings of deploy Azure Functions task.
You can add a File Transform task before the deploy Azure Functions task. Then define the variables(eg. KeyVaultSettings.ClientId) in your pipeline variables.
Then set the Package or folder, file format and Target files in File Transform task. See below:
This is what I've done in my Azure Functions pipeline (it's yaml, but you'll get the idea).
Create one stage per environment in your pipeline
Create your pipelines variables and asign a different value based on scope (stage)
Create a configuration entry (see picture) in your pipeline and asign the variable value.
Consume the configuration entry in your Azure Function (in my case I use Environmental Variables for that)
Use pipeline environment in your azure function configuration
I created an environment variable in Azure App Service. However, I'm not able to pick the value from Azure while it is published.
So I added it to the appsettings.json, and it works.
My question would be, if I add an environment variable in Azure configuration settings, shall I add it in the appsettings.json as well, or is having it in the Azure environment settings enough?
When I navigate to
https://your-web-name.scm.azurewebsites.net/Env.cshtml
I can clearly see the variable is present there. Why is this not being picked up in the code? Am I doing something wrong?
appSettings["MailKitPassword"] <-- This is not being picked up, so I have to hard-code it.
In order to retrieve it you should use Environment.GetEnvironmentVariable("APPSETTING_MailKitPassword")
As Thiago Mentioned, you need to use GetEnvironmentVariable method to retrieve the AppSettings values,
so your code should be
Environment.GetEnvironmentVariable("APPSETTING_MailKitPassword")
However i would recommend you to store the passwords in Azure KeyVault.