Reputation: 8407
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.
Upvotes: 5
Views: 5153
Reputation: 2110
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.
Upvotes: 9
Reputation: 14324
There are three ways to implement it.
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)
{
}
With Azure Functions Core Tools, only for version 1.x
func run <functionName>
{
"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.
Upvotes: 9
Reputation: 8407
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
.
Upvotes: 2