如何以编程方式启用/禁用 Azure 功能 [英] How to Enable/Disable Azure Function programmatically
问题描述
有没有办法以编程方式启用/禁用 Azure 功能?
Is there a way to programmatically enable/disable an Azure function?
我可以使用管理"部分下的门户启用/禁用功能,这会导致将请求发送到 https://<myfunctionapp>.scm.azurewebsites.net/api/functions/<我的功能>
I can enable/disable a function using the portal under the "Manage" section, which causes a request to be sent to https://<myfunctionapp>.scm.azurewebsites.net/api/functions/<myfunction>
JSON 负载看起来有点像:
The JSON payload looks a bit like:
{
"name":"SystemEventFunction",
"config":{
"disabled":true,
"bindings":[
// the bindings for this function
]
}
// lots of other properties (mostly URIs)
}
我正在门户之外创建一个管理工具,允许用户启用和禁用功能.
I'm creating a management tool outside of the portal that will allow users to enable and disable functions.
希望我可以避免手动创建 JSON 负载,所以我想知道 SDK(WebJobs??)中是否有具有此功能的东西.
Hoping I can avoid creating the JSON payload by hand, so I'm wondering if there is something in an SDK (WebJobs??) that has this functionality.
推荐答案
不,这目前是不可能的.function.json 中的 disabled
元数据属性决定了某个功能是否启用.当您在门户中启用/禁用时,门户只会更新该值.
No, this is not possible currently. The disabled
metadata property in function.json is what determines whether a function is enabled. The portal just updates that value when you enable/disable in the portal.
不确定它是否能满足您的需求,但我会指出还有一个 host.json functions
数组可用于控制将要加载的函数集(记录在此处).因此,例如,如果您只希望启用 10 个函数中的 2 个,则可以将此属性设置为仅包含这 2 个函数名称的数组(例如 "functions": [ "QueueProcessor", "GitHubWebHook" ]
),并且只有那些会被加载/启用.但是,这与启用/禁用略有不同,因为您将无法通过门户调用排除的功能,而您可以通过门户调用禁用功能.
Not sure if it will meet your needs, but I'll point out that there is also a host.json functions
array that can be used to control the set of functions that will be loaded (documented here). So for example, if you only wanted 2 of your 10 functions enabled, you could set this property to an array containing only those 2 function names (e.g. "functions": [ "QueueProcessor", "GitHubWebHook" ]
), and only those will be loaded/enabled. However, this is slightly different than enable/disable in that you won't be able to invoke the excluded functions via the portal, whereas you can portal invoke disabled functions.
这篇关于如何以编程方式启用/禁用 Azure 功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!