How to Disable Azure Functions for Local and Azure Cloud

How to Disable Azure Functions for Local and Azure Cloud

When working with Azure Functions, you often have multiple functions as part of a single function app. When debugging or running the function app locally, all the associated functions start and run together. However, during debugging, you may want to disable the functions that you are not interested in. This article covers how to disable a function in Azure Functions when running locally and in Azure.

Disabling a function locally

The best way to disable a function while running locally is by using an app setting in the local.settings.json file in the format AzureWebJobs.<FUNCTION_NAME>.Disabled set to true. For example, if you have three functions: ProcessOrder, SendEmailNotification, and GeneratePDFReport, and you want to disable only the SendEmailNotification function, add the following entry to the Values collection in the local.settings.json file:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    // The below line disables the 'SendEmailNotification' function
    "AzureWebJobs.SendEmailNotification.Disabled": true
  }
}

While there are other ways to disable functions, these methods can vary depending on the language and runtime version used. Therefore, the application setting mentioned above is the recommended approach for all languages and all runtime versions.

Disabling a function in Azure

To disable a function in a deployed Azure Function App, the same configuration method as mentioned above can be used.

Going by the same example as above, if you have three functions: ProcessOrder, SendEmailNotification, and GeneratePDFReport, and you want to disable only the SendEmailNotification function, navigate to the Configuration tab of your Azure Function App and add a "New Application Setting" with the name AzureWebJobs.SendEmailNotification.Disabled and Value true. If you want to re-enable the function, simply change the value to false

Another option is to use the "Disable" button in the Azure Portal against the function to disable it.

Once the function is disabled, any attempt to invoke it will result in an HTTP 404 Not Found error.

In conclusion, knowing how to disable Azure Functions locally and in the Azure cloud is essential for efficient development and debugging. By leveraging app settings and configuration options, you can selectively disable specific functions, optimizing your workflow and improving overall performance. With this knowledge, you gain control over your function app's behavior, maximizing productivity in your Azure projects.