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

天涯浪子 提交于 2019-12-22 04:18:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/37877609/azure-functions-can-environment-variables-be-used-in-function-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!