如何以编程方式启用/禁用Azure功能 [英] How to Enable/Disable Azure Function programmatically

查看:97
本文介绍了如何以编程方式启用/禁用Azure功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式启用/禁用Azure功能?

Is there a way to programmatically enable/disable an Azure function?

我可以使用管理"部分下的门户启用/禁用功能,这将导致请求发送到https://<myfunctionapp>.scm.azurewebsites.net/api/functions/<myfunction>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆