Skip to content

Commit f3a7ef6

Browse files
committed
Freshness and remove the Other ways section
1 parent a8cc274 commit f3a7ef6

File tree

1 file changed

+23
-80
lines changed

1 file changed

+23
-80
lines changed

articles/azure-functions/disable-function.md

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22
title: How to disable functions in Azure Functions
33
description: Learn how to disable and enable functions in Azure Functions.
44
ms.topic: conceptual
5-
ms.date: 12/01/2022
5+
ms.date: 03/12/2024
66
ms.custom: devx-track-csharp
77
---
88

99
# How to disable functions in Azure Functions
1010

11-
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.
11+
This article explains how to disable a function in Azure Functions. To *disable* a function means to make the runtime ignore the event intended to trigger the function. This ability lets you prevent a specific function from running without having to modify and republish the entire function app.
1212

13-
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 several ways, including by using the [Azure CLI](/cli/azure/) and from your function's **Overview** tab in the [Azure portal](https://portal.azure.com).
13+
You can disable a function in place by creating an app setting in the format `AzureWebJobs.<FUNCTION_NAME>.Disabled` set to `true`. You can create and modify this application setting in several ways, including by using the [Azure CLI](/cli/azure/), [Azure PowerShell](/powershell/azure/), and from your function's **Overview** tab in the [Azure portal](https://portal.azure.com).
14+
15+
Changes to application settings cause your function app to restart. For more information, see [App settings reference for Azure Functions](functions-app-settings.md).
1416

1517
## Disable a function
1618

17-
# [Portal](#tab/portal)
19+
Use one of these modes to create an app setting that disables an example function named `QueueTrigger`:
20+
21+
### [Portal](#tab/portal)
1822

19-
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.
23+
Use the **Enable** and **Disable** buttons on the function's **Overview** page. These buttons work by changing the value of the `AzureWebJobs.QueueTrigger.Disabled` app setting. The function-specific app setting is created the first time a function is disabled.
2024

2125
![Function state switch](media/disable-function/function-state-switch.png)
2226

@@ -25,7 +29,7 @@ Even when you publish to your function app from a local project, you can still u
2529
> [!NOTE]
2630
> Disabled functions can still be run by calling the REST endpoint using a master key. To learn more, see [Run a disabled function](#run-a-disabled-function). This means that a disabled function still runs when started from the **Test/Run** window in the portal using the **master (Host key)**.
2731
28-
# [Azure CLI](#tab/azurecli)
32+
### [Azure CLI](#tab/azurecli)
2933

3034
In the Azure CLI, you use the [`az functionapp config appsettings set`](/cli/azure/functionapp/config/appsettings#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` and setting it to `true`.
3135

@@ -43,7 +47,7 @@ az functionapp config appsettings set --name <myFunctionApp> \
4347
--settings AzureWebJobs.QueueTrigger.Disabled=false
4448
```
4549

46-
# [Azure PowerShell](#tab/powershell)
50+
### [Azure PowerShell](#tab/powershell)
4751

4852
The [`Update-AzFunctionAppSetting`](/powershell/module/az.functions/update-azfunctionappsetting) command adds or updates an application setting. The following command disables a function named `QueueTrigger` by creating an app setting named `AzureWebJobs.QueueTrigger.Disabled` and setting it to `true`.
4953

@@ -58,19 +62,19 @@ Update-AzFunctionAppSetting -Name <FUNCTION_APP_NAME> -ResourceGroupName <RESOUR
5862
```
5963
---
6064

61-
## Functions in a slot
65+
## Disable functions in a slot
6266

63-
By default, app settings also apply to apps running in deployment slots. You can, however, override the app setting used by the slot by setting a slot-specific app setting. For example, you might want a function to be active in production but not during deployment testing, such as a timer triggered function.
67+
By default, app settings also apply to apps running in deployment slots. You can, however, override the app setting used by the slot by setting a slot-specific app setting. For example, you might want a function to be active in production but not during deployment testing. It's common to disable timer triggered functions in slots to prevent simultaneous executions.
6468

6569
To disable a function only in the staging slot:
6670

67-
# [Portal](#tab/portal)
71+
### [Portal](#tab/portal)
6872

69-
Navigate to the slot instance of your function app by selecting **Deployment slots** under **Deployment**, choosing your slot, and selecting **Functions** in the slot instance. Choose your function, then 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.
73+
Navigate to the slot instance of your function app by selecting **Deployment slots** under **Deployment**, choosing your slot, and selecting **Functions** in the slot instance. Choose your function, then 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 you disable the function.
7074

71-
You can also directly add the app setting named `AzureWebJobs.<FUNCTION_NAME>.Disabled` with value of `true` in the **Configuration** for the slot instance. When you add a slot-specific app setting, make sure to check the **Deployment slot setting** box. This maintains the setting value with the slot during swaps.
75+
You can also directly add the app setting named `AzureWebJobs.<FUNCTION_NAME>.Disabled` with value of `true` in the **Configuration** for the slot instance. When you add a slot-specific app setting, make sure to check the **Deployment slot setting** box. This option maintains the setting value with the slot during swaps.
7276

73-
# [Azure CLI](#tab/azurecli)
77+
### [Azure CLI](#tab/azurecli)
7478

7579
```azurecli-interactive
7680
az functionapp config appsettings set --name <FUNCTION_APP_NAME> \
@@ -85,7 +89,7 @@ az functionapp config appsettings set --name <myFunctionApp> \
8589
--slot-settings AzureWebJobs.QueueTrigger.Disabled=false
8690
```
8791

88-
# [Azure PowerShell](#tab/powershell)
92+
### [Azure PowerShell](#tab/powershell)
8993

9094
Azure PowerShell currently doesn't support this functionality.
9195

@@ -101,89 +105,28 @@ You can still cause a disabled function to run by supplying the [master key](fun
101105

102106
To learn more about the master key, see [Obtaining keys](functions-bindings-http-webhook-trigger.md#obtaining-keys). To learn more about calling non-HTTP triggered functions, see [Manually run a non HTTP-triggered function](functions-manually-run-non-http.md).
103107

104-
## local.settings.json
108+
## Disable functions locally
105109

106-
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:
110+
Functions can be disabled in the same way when running locally. To disable a function named `QueueTrigger`, add an entry to the Values collection in the local.settings.json file, as follows:
107111

108112
```json
109113
{
110114
"IsEncrypted": false,
111115
"Values": {
112116
"FUNCTIONS_WORKER_RUNTIME": "python",
113117
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
114-
"AzureWebJobs.HttpExample.Disabled": true
118+
"AzureWebJobs.QueueTrigger.Disabled": true
115119
}
116120
}
117121
```
118122

119-
## Other methods
120-
121-
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.
122-
123-
### C# class libraries
124-
125-
In a class library function (`In-process` model), 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:
126-
127-
```csharp
128-
public static class QueueFunctions
129-
{
130-
[Disable("MY_TIMER_DISABLED")]
131-
[FunctionName("QueueTrigger")]
132-
public static void QueueTrigger(
133-
[QueueTrigger("myqueue-items")] string myQueueItem,
134-
TraceWriter log)
135-
{
136-
log.Info($"C# function processed: {myQueueItem}");
137-
}
138-
}
139-
```
140-
141-
> [!NOTE]
142-
> [Disable] attribute is not available in Isolated worker model.
143-
144-
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.
145-
146-
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.
147-
148-
### Functions 1.x - scripting languages
149-
150-
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:
151-
152-
```json
153-
{
154-
"bindings": [
155-
{
156-
"type": "queueTrigger",
157-
"direction": "in",
158-
"name": "myQueueItem",
159-
"queueName": "myqueue-items",
160-
"connection":"MyStorageConnectionAppSetting"
161-
}
162-
],
163-
"disabled": true
164-
}
165-
```
166-
or
167-
168-
```json
169-
"bindings": [
170-
...
171-
],
172-
"disabled": "IS_DISABLED"
173-
```
174-
175-
In the second example, the function is disabled when there's an app setting that is named IS_DISABLED and is set to `true` or 1.
176-
177-
>[!IMPORTANT]
178-
>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.
179-
180123
## Considerations
181124

182125
Keep the following considerations in mind when you disable functions:
183126

184-
+ 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 and [in the portal](#run-a-disabled-function).
127+
+ When you disable an HTTP triggered function by using the methods described in this article, the endpoint can still be accessed when running on your local computer and [in the portal](#run-a-disabled-function).
185128

186-
+ At this time, function names that contain a hyphen (`-`) can't be disabled when running on Linux plan. If you need to disable your functions when running on Linux plan, don't use hyphens in your function names.
129+
+ At this time, function names that contain a hyphen (`-`) can't be disabled when running on Linux. If you plan to disable your functions when running on Linux, don't use hyphens in your function names.
187130

188131
## Next steps
189132

0 commit comments

Comments
 (0)