I have an azure function with type as serviceBusTrigger. Right now the value of "topicName" is considered as a string. I want to add the topicName as an enviroment variable (AZURE_FUNC_TOPIC_NAME) in app.settings.json. would like to have value of this variable AZURE_FUNC_TOPIC_NAME to be assigned to the key topicName in below function.json How could i achieve it?
{
"bindings": [
{
"name": "mySbMsg",
"type": "serviceBusTrigger",
"direction": "in",
"topicName": "AZURE_SERVICE_BUS_TOPIC",
"connection": "",
"subscriptionName": ""
}
],
"disabled": false
}
In local.settings.json file, define your variables like topic name in the key-value format and get that environment variable in your function code.
To get an environment variable or an app setting value, use System.Environment.GetEnvironmentVariable, as shown below.
public static string GetEnvironmentVariable(string name)
{
return name + ": " +
System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
}