Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions how to add application settings to bindings

I'm trying to add some custom binding using my app settings for my Azure Function. I need to receive only string a string from my settings.

enter image description here

I would like to get simpleValue from my settings.

{
   "bindings": [
    {
      "name": "someValue",
      "type": "stringSetting",
      "connection": "simpleValue",
      "direction": "in"
    }
  ],
  "disabled": false
}

and the get it in Run method:

static void GetOrders(TraceWriter log, string someValue)
{
    log.Info(someValue);
}

Is it even possible. Maybe there is other way to do it?

like image 478
Meroz Avatar asked Oct 26 '16 11:10

Meroz


People also ask

How do you specify app settings for an Azure functions project?

To find the application settings, see Get started in the Azure portal. The Application settings tab maintains settings that are used by your function app. You must select Show values to see the values in the portal. To add a setting in the portal, select New application setting and add the new key-value pair.

How do I connect to Azure app configuration?

In the upper-left corner of the home page, select Create a resource. In the Search services and marketplace box, enter App Configuration and select Enter. Select App Configuration from the search results, and then select Create. Select the Azure subscription that you want to use to test App Configuration.

How do I add local settings json to my project?

In your project, open the local. settings. json file and set the value of the AzureWebJobsStorage key to the connection string you copied. Repeat the previous step to add unique keys to the Values array for any other connections required by your functions.


2 Answers

App Settings configurations can be referred in binding json as %MY_CUSTOM_CONFIG% - enclosed within percent symbols.

Note that the connection property of triggers and bindings is a special case and automatically resolves values as app settings, without percent signs. https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings

like image 193
Rima Avatar answered Oct 05 '22 21:10

Rima


I already found the solution. Just add:

using System.Configuration;

and add this line to code with the key ("simpleValue") value:

ConfigurationManager.AppSettings["simpleValue"]
like image 20
Meroz Avatar answered Oct 05 '22 23:10

Meroz