4

If I want to launch all available functions in the dev environment, I simply do:

 func host start

Is there a way to choose a subset of the available functions, without having to move the intended-to-be-deactivated ones out of the working directory etc.?

PS I am using Python for the Function itself.

jtlz2
  • 7,700
  • 9
  • 64
  • 114

3 Answers3

8

I use func start --functions [a space separated list of functions]

This is with azure-functions-core-tools@3

According to:

--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.
Esteban Rincon
  • 2,040
  • 3
  • 27
  • 44
6

There are three ways to implement it.

  1. Disable functions:

One is modifying the function.json:

"bindings": [
    ...
],
"disabled": "IS_DISABLED"

Another is use Disable attribute to prevent a function from being triggered.

    [Disable]
 [FunctionName("Function")]
 [NoAutomaticTrigger]
 public static void Function(string input, TraceWriter log)
{
}
  1. With Azure Functions Core Tools, only for version 1.x

    func run <functionName>

  2. host.json:

    {
     "functions": [ "QueueProcessor", "GitHubWebHook" ]
    }
    

Update:

4: as jtlz2 answered, this way is for disable functions locally with local.settings.json.

{
  "Values": {
     "AzureWebJobs.MyFunctionName.Disabled": true
     "AzureWebJobs.MyFunctionName2.Disabled": false
   }
}

**Update:**as @ahmelsayed explains something about there are many options to call only one function, so i update it here.

"Disabled" is meant to be used to dynamically turn a function on or off. The runtime will still load the function, and will display any errors or issues with the function (incorrect settings etc), but will not execute the code. There are many ways to enable/disable a function because some want to keep that in source control and for some it's a devops operation

The functions array in host.json is something I wasn't initially aware of. It was added to the runtime for the convenience of the runtime developers who have a large folder of samples that they wanted to be able to load only a subset of. This completely ignores functions that are not listed. They won't be indexed or loaded in anyway.

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • Oops, I posted a (different) answer but to the wrong question(!). Mine adds a fourth way - if you might add it to your answer then yours would be hard to beat? Also, do you know why there are quite so many options..? – jtlz2 May 20 '19 at 09:25
  • @jtlz2, some ways are for the Function on the azure and some for only testing. And the host.json the doc mentions it's only used for running locally. – George Chen May 20 '19 at 09:31
  • Fair enough - and my post was specific about dev. Thanks! – jtlz2 May 20 '19 at 09:32
  • @jtlz2, if this could help you, you could mark it as the answer. Thanks! – George Chen May 20 '19 at 09:33
  • If you are able to add my answer into yours in fact, then I can and will be in a position to accept! :) – jtlz2 May 20 '19 at 11:43
  • Fantastic - thank you so so much, and for your speed reply. Answer accepted! – jtlz2 May 20 '19 at 15:18
  • George please see comment below my answer. Thanks! – jtlz2 May 21 '19 at 10:13
  • 1
    @jtlz2, please check the host.json way link I paste, I believe they are the same way. – George Chen May 21 '19 at 12:11
  • George there is some extra info from @ahmelsayed - perhaps you can add it to your answer as well? :) – jtlz2 May 22 '19 at 07:02
2

It seems there has been some consternation over disabling Functions lately.

As pointed out at https://github.com/Azure/Azure-Functions/issues/736#issuecomment-471072316, one can make use of local.settings.json to achieve this. Simply add to it:

{
  "Values": {
    "AzureWebJobs.MyFunctionName.Disabled": true
    "AzureWebJobs.MyFunctionName2.Disabled": false
  }
}

etc.

I'd be interested to hear if there is a better way, e.g. setting it from the command line when executing func host start.

jtlz2
  • 7,700
  • 9
  • 64
  • 114
  • 1
    Another way you can do that by adding the functions you want to run in your host.json like `{ "functions": [ "MyFunctionName" ] }`. That will ONLY load `MyFunctionName` I was thinking of adding a `--functions ` to `func start` but I wasn't sure if there was a need for it. Please feel free to open an ask on the core-tools repo https://github.com/Azure/azure-functions-core-tools/issues and I can take care of it – ahmelsayed May 20 '19 at 23:08
  • @ahmelsayed Amazing, will try to! I wonder if the author of the other answer George Chen can incorporate this into his answer? Question: Why are there quite so many options / any plan to rationalise it? :\ – jtlz2 May 21 '19 at 10:12
  • 1
    Apologies - George already has that in his answer of course. Your proposal would be amazing - will open a ticket now. Thanks! – jtlz2 May 21 '19 at 12:46
  • 1
    Yep, George answer is pretty complete with everything possible now :) – ahmelsayed May 21 '19 at 20:01
  • 1
    about the existence of many options, they are all meant for slightly different scenarios. It's pretty confusing though because the scenarios are very similar with one or two slight differences. "Disabled" is meant to be used to dynamically turn a function on or off. The runtime will still load the function, and will display any errors or issues with the function (incorrect settings etc), but will not execute the code. There are many ways to enable/disable a function because some want to keep that in source control and for some it's a devops operation – ahmelsayed May 21 '19 at 20:04
  • 1
    The `functions` array in host.json is something I wasn't initially aware of. It was added to the runtime for the convenience of the runtime developers who have a large folder of [samples](https://github.com/Azure/azure-functions-host/tree/dev/sample) that they wanted to be able to load only a subset of. This completely ignores functions that are not listed. They won't be indexed or loaded in anyway. I initially asked for it to be removed because it was confusing, but then it enabled some scenarios like this not to mention that removing it would be an unnecessary breaking change for someone. – ahmelsayed May 21 '19 at 20:10
  • @ahmelsayed Huge thanks for the clarity - perhaps George can add it to his answer?? :) – jtlz2 May 22 '19 at 07:02