Azure Functions:如何在本地开发环境中仅启动特定函数?

jtl*_*lz2 5 azure-functions azure-functions-runtime

如果我想在开发环境中启动所有可用的功能,我只需执行以下操作:

 func host start
Run Code Online (Sandbox Code Playgroud)

有没有办法选择可用功能的子集,而不必将打算停用的功能移出工作目录等?

PS 我使用 Python 作为函数本身。

est*_*con 9

我用func start --functions [a space separated list of functions]

这是与azure-functions-core-tools@3

根据:

--port [-p]        Local port to listen on. Default: 7071
--cors             A comma separated list of CORS origins with no spaces. Example: https://functions.azure.com,https://functions-staging.azure.com
--cors-credentials Allow cross-origin authenticated requests (i.e. cookies and the Authentication header)
--timeout [-t]     Timeout for on the functions host to start in seconds. Default: 20 seconds.
--useHttps         Bind to https://localhost:{port} rather than http://localhost:{port}. By default it creates and trusts a certificate.
--cert             for use with --useHttps. The path to a pfx file that contains a private key
--password         to use with --cert. Either the password, or a file that contains the password for the pfx file
--language-worker  Arguments to configure the language worker.
--no-build         Do no build current project before running. For dotnet projects only. Default is set to false.
--enableAuth       Enable full authentication handling pipeline.
--functions        A space seperated list of functions to load.
Run Code Online (Sandbox Code Playgroud)


Geo*_*hen 7

有三种方法可以实现它。

  1. 禁用功能

一是修改function.json:

"bindings": [
    ...
],
"disabled": "IS_DISABLED"
Run Code Online (Sandbox Code Playgroud)

另一种是使用Disable属性来防止函数被触发。

    [Disable]
 [FunctionName("Function")]
 [NoAutomaticTrigger]
 public static void Function(string input, TraceWriter log)
{
}
Run Code Online (Sandbox Code Playgroud)
  1. 使用Azure Functions Core Tools,仅适用于版本 1.x

    func run <functionName>

  2. 主机.json

    {
     "functions": [ "QueueProcessor", "GitHubWebHook" ]
    }
    
    Run Code Online (Sandbox Code Playgroud)

更新:

4:正如 jtlz2 回答的那样,这种方法用于在本地禁用local.settings.json.

{
  "Values": {
     "AzureWebJobs.MyFunctionName.Disabled": true
     "AzureWebJobs.MyFunctionName2.Disabled": false
   }
}
Run Code Online (Sandbox Code Playgroud)

**更新:**正如 @ahmelsayed 解释的那样,有很多选项可以仅调用一个函数,所以我在这里更新它。

“禁用”意味着用于动态打开或关闭功能。运行时仍将加载该函数,并显示该函数的任何错误或问题(不正确的设置等),但不会执行代码。有很多方法可以启用/禁用某个功能,因为有些人希望将其保留在源代码控制中,而有些人则希望将其保留在 DevOps 操作中

host.json 中的数组functions是我最初没有意识到的。它被添加到运行时是为了方便运行时开发人员,他们有一个大文件夹的示例,他们希望能够仅加载其中的一个子集。这完全忽略了未列出的功能。无论如何,它们都不会被索引或加载。