Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure-functions: Can environment variables be used in function.json?

I'm currently using the git push deployment option to deploy a few copies of an azure-function. The function's function.json file has multiple "connection" entries linking to different storage accounts (i.e. for a blob trigger & table output). In different copies of the deployed function I'd like to connect to different storage accounts. Is there any special syntax that can be used in function.json to populate the "connection" string from an environment variable?

I guess an alternative would be to edit function.json as part of a custom kudu step, but environment variables seems more consistent with the other azure app service offerings.

like image 813
Rufus Nelson Avatar asked Jun 17 '16 09:06

Rufus Nelson


People also ask

What is function json in Azure function?

The function. json file defines the function's trigger, bindings, and other configuration settings. Every function has one and only one trigger. The runtime uses this config file to determine the events to monitor and how to pass data into and return data from a function execution.

What is the environment in json?

The env. json file is a project-specific list of accessible variables. This file is the ideal place to store secret keys, project-wide properties, or anything else you want to obfuscate or share between your files.

How do I store environment variables in Azure?

To set environment variables when you start a container in the Azure portal, specify them in the Advanced page when you create the container. Under Environment variables, enter NumWords with a value of 5 for the first variable, and enter MinLength with a value of 8 for the second variable.


1 Answers

This already works, and is actually the recommended way for you to handle connection strings, since you don't want those checked in with your source code. You can use an app setting name for the connection value, and we'll resolve it. In the following EventHub triggered function, the values MyEventHubReceiver, MyEventHubSender and MyEventHubPath will be auto resolved from app settings:

    "bindings": [
        {
            "type": "eventHubTrigger",
            "name": "input",
            "direction": "in",
            "connection": "MyEventHubReceiver",
            "path": "%MyEventHubPath%"
        },
        {
            "type": "eventHub",
            "name": "output",
            "direction": "out",
            "connection": "MyEventHubSender",
            "path": "%MyEventHubPath%"
        }
    ]
}

In general, most of the binding properties support the %% resolution syntax, allowing you to store the actual values in app settings for both security as well as configurability.

like image 144
mathewc Avatar answered Oct 20 '22 16:10

mathewc