How to disable functions in Azure Functions

This article explains how to disable a function in Azure Functions. To disable a function means to make the runtime ignore the automatic trigger that's defined for the function. This lets you prevent a specific function from running without stopping the entire function app.

The recommended way to disable a function is with an app setting in the format AzureWebJobs.<FUNCTION_NAME>.Disabled set to true. You can create and modify this application setting in a number of ways, including by using the Azure CLI and from your function's Overview tab in the Azure portal.

Note

When you disable an HTTP triggered function by using the methods described in this article, the endpoint may still by accessible when running on your local computer.

Use the Azure CLI

In the Azure CLI, you use the az functionapp config appsettings set command to create and modify the app setting. The following command disables a function named QueueTrigger by creating an app setting named AzureWebJobs.QueueTrigger.Disabled set it to true.

az functionapp config appsettings set --name <myFunctionApp> \
--resource-group <myResourceGroup> \
--settings AzureWebJobs.QueueTrigger.Disabled=true

To re-enable the function, rerun the same command with a value of false.

az functionapp config appsettings set --name <myFunctionApp> \
--resource-group <myResourceGroup> \
--settings AzureWebJobs.QueueTrigger.Disabled=false

Use the Portal

You can also use the Enable and Disable buttons on the function's Overview page. These buttons work by changing the value of the AzureWebJobs.<FUNCTION_NAME>.Disabled app setting. This function-specific setting is created the first time it's disabled.

Function state switch

Even when you publish to your function app from a local project, you can still use the portal to disable functions in the function app.

Note

The portal-integrated testing functionality ignores the Disabled setting. This means that a disabled function still runs when started from the Test window in the portal.

local.settings.json

Functions can be disabled in the same way when running locally. To disable a function named HttpExample, add an entry to the Values collection in the local.settings.json file, as follows:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true", 
    "AzureWebJobs.HttpExample.Disabled": "true"
  }
}

Other methods

While the application setting method is recommended for all languages and all runtime versions, there are several other ways to disable functions. These methods, which vary by language and runtime version, are maintained for backward compatibility.

C# class libraries

In a class library function, you can also use the Disable attribute to prevent the function from being triggered. This attribute lets you customize the name of the setting used to disable the function. Use the version of the attribute that lets you define a constructor parameter that refers to a Boolean app setting, as shown in the following example:

public static class QueueFunctions
{
    [Disable("MY_TIMER_DISABLED")]
    [FunctionName("QueueTrigger")]
    public static void QueueTrigger(
        [QueueTrigger("myqueue-items")] string myQueueItem, 
        TraceWriter log)
    {
        log.Info($"C# function processed: {myQueueItem}");
    }
}

This method lets you enable and disable the function by changing the app setting, without recompiling or redeploying. Changing an app setting causes the function app to restart, so the disabled state change is recognized immediately.

There's also a constructor for the parameter that doesn't accept a string for the setting name. This version of the attribute isn't recommended. If you use this version, you must recompile and redeploy the project to change the function's disabled state.

Functions 1.x - scripting languages

In version 1.x, you can also use the disabled property of the function.json file to tell the runtime not to trigger a function. This method only works for scripting languages such as C# script and JavaScript. The disabled property can be set to true or to the name of an app setting:

{
    "bindings": [
        {
            "type": "queueTrigger",
            "direction": "in",
            "name": "myQueueItem",
            "queueName": "myqueue-items",
            "connection":"MyStorageConnectionAppSetting"
        }
    ],
    "disabled": true
}

or

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

In the second example, the function is disabled when there is an app setting that is named IS_DISABLED and is set to true or 1.

Important

The portal uses application settings to disable v1.x functions. When an application setting conflicts with the function.json file, an error can occur. You should remove the disabled property from the function.json file to prevent errors.

Next steps

This article is about disabling automatic triggers. For more information about triggers, see Triggers and bindings.