Adding connection settings during runtime for Azure Function App - azure

I'm searching for ways to modify and edit app settings for Azure function during runtime.
from the links below, I was able to find how to add bindings locally and add connection settings through azure portal or Azure Cli
https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file
https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library#environment-variables
However, I'm searching for ways to generate new connection setting variables as well as new bindings at runtime.
The use case would be, where we need to onboard users without manually interacting with the Azure function app configuration.
I also tried modifying it thorough an example given in below link:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#environment-variables
I was able to modify the variable temporarily, but it appears that it loses the changes as soon as the run gets terminated (also, it didn't work when I published the app on Azure).
Is there way to accomplish this during runtime?
My set up is to have two azure functions:
1. dedicated to modifying app settings if change is detected in CosmosDB where new user information is added.
2. dedicated sending messages, but generating bindings based on app configurations added by azure function 1.
My initial thoughts were to store the whole app settings in cosmosDB and generate appsettings based on that document at every onetime, but I'm pretty sure there is better ways to do this.
also, it looks like my connection strings in local.settings.json don't get reflected when I actually publish them. what am I missing?
Thanks, in advance :)

Related

Unable to save Application Settings in Azure Function App which I was able to save successfully previously

I am getting an error message while trying to save application settings which I have added for the Function App.
I had created a function app and have been using it for Azure functions. I had previously successfully added Application setting for a config parameter in the azure function application settings and have been using this in code. This time when I went to add another application settings suddenly it started giving the error "Cannot change the site to the App Service Plan EastUSPlan due to hosting constraints". Nothing has been changed and on previous occassions, I was able to add application settings this way. I have tried following the solutions in below link on using previous or pre URL for azure functions and also to clear cache and try on different browsers.
Azure App Service : can't save application settings
I want to successfully save a new config property in azure function as I was doing previously by adding an entry under Application Settings. How can I save the application settings entry in such a case?
Thank You.
One alternative workaround which worked for me was to delete the function app, create a new function app by the same name, add the application settings in the newly created function app (before deploying any code). It allowed me to save the application settings. Only after this, I deployed the code.
For now to unblock yourself you can use REST API :
Web Apps - Update Application Settings
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/appsettings?api-version=2016-08-01
But Share the screen shot of the error from the portal. Also I may required further information from your side if the issue still persist so that I can get it rectified from portal perspective also.

Fully automating Microsoft bot framework deployment using ARM (App settings get removed and functionality is missing)

I'm currently working on a challenge where I'd like to fully automate the deployment of a Bot Framework application.
Currently we've set it all up to correctly fill the resource group in Azure with:
1. The Bot
2. The AppService handling requests from the Bot
3. An application that uses the DirectLineChannel to forward the conversation from an Amazon Alexa client
All these application need some manual steps to be fully setup though:
The Bot
a. Create Skype Channel
b. Create a Direct Line Channel and copy the DirectLineSecret to be used later
c. Setting up OAuth for the bot
The App Service for the Direct Line Channel
a. Create a new AppSetting named DirectLineSecret and paste the earlier copied value in here
Part one can be done once so it doesn't have to be done every time, but the second step always needs to be done as the AppSettings get removed by the ARM template every deployment.
An easy solution would be to just include the values inside the parameter file for ARM but that would make my source code dependent on what environments it will deploy to. A second option would be to create a PowerShell script to fill in the AppSettings after the deployment but that would still need to somehow find out what the DirectLineSecret is and then create an AppSetting for it.
Does anyone have any other suggestions regarding this? (Ideally where my code wouldn't have to be changed whenever I want to deploy to a new environment).
ARM Templates declare a "state" or end goal for a resource. So if you declare "no app settings" in the template that's what you'll get. Declarative is a bit of a mindset change.
If you need different settings for different environments then you would use parameters to replace that things that need to change from one env to the next. Assuming you're automated, that automation pipeline is likely aware of the env it's deploying to and can set the parameters values accordingly.
That help?

How to share application settings between app services in Azure?

I have several App Services in Azure: development, test, and production. I would like to share some application settings between them like variable sets in Octopus.
Let's say I have a key A which should be same in all App Services. I would like to set its value in one place but seems that I have to configure it to each App Service. When A is changed, I have to change it to everywhere instead of having one common place to change it. Is there some way to do this?
No built-in way, app settings are part of the App Service resource.
You will need to put the settings in a common database or file.
Azure Key Vault can be used for sensitive settings and table storage/blob storage works well for other settings. Azure SQL is also an option.
Your app will then need to load these settings at startup.
This is also a documented cloud design pattern: https://learn.microsoft.com/en-us/azure/architecture/patterns/external-configuration-store

Is it possible to update configuration settings programmatically?

We are experimenting with deploying an MVC app as an Azure web role. Currently the app is being hosted locally on our server. It has a few appSettings in Web.Config that can be changed by the users as part of the "Administration" module of the application.
I know this isn't a good practice for Azure because there will potentially be multiple instances of the application running with multiple Web.Configs, which makes updating them all a nightmare (if not impossible). My understanding is that the ConfigurationSettings specified in the service definition should be used instead of Web.Config so that settings are defined globally in one place that all the instances of the application can access.
My question is is it possible to programmatically update ConfigurationSettings similar to the way we update Web.Config settings, or would it be better for us to move those settings into a database or something else?
Yes, but unfortunately it is definitely not simple to do.
Follow this URL: http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx
It talks about a Svc Management API call that you can make to read/write the Service Configuration. It is a 64-base string which you'll need to decode, find XML flags in it that you want to change and re-encode it back and send it back to the API.
Not pleasant, but doable.

Changing/retrieving configuration settings on role start (Azure)

I'm trying to make a service to more easily configure configuration values on Azure applications. Right now, if I want to change a setting that it the same over 7 different environments, I have to change it in 7 different .cscfg files.
My thought is I can create a webservice, that the application will query for its configuration values. The webservice will look in a storage place, like Azure Tables, and return the correct configuration values.
I've been able to integrate this into a deployment script pretty easily (package the app, get the settings, change the cscfg file, deploy). The problem with that is every time you want to change a setting, you have to redeploy.
Finally the question - Is there a way I can retrieve the configuration settings after the application starts, on role start? It would of course need a base set of settings for the app to start. Retrieving the settings from the web service on application start would be good. Any way that I don't have to redeploy the application and that it will retrieve them automatically will work.
Thanks in advance!
Just use the .cscfg for the minimum set (common to all environment) of configurable settings. The use your web services for rest of the configurations. And don't modify your .cscfg. Just have a settings provider that retrieves settings from web service (via polling or message signalling - pub/sub model). And have a reinitialize settings procedure in place for this settings provider and all the services/components that rely on configurable settings.

Resources