You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/disable-function.md
+23-80Lines changed: 23 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,21 +2,25 @@
2
2
title: How to disable functions in Azure Functions
3
3
description: Learn how to disable and enable functions in Azure Functions.
4
4
ms.topic: conceptual
5
-
ms.date: 12/01/2022
5
+
ms.date: 03/12/2024
6
6
ms.custom: devx-track-csharp
7
7
---
8
8
9
9
# How to disable functions in Azure Functions
10
10
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.
12
12
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).
14
16
15
17
## Disable a function
16
18
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)
18
22
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.
20
24
21
25

22
26
@@ -25,7 +29,7 @@ Even when you publish to your function app from a local project, you can still u
25
29
> [!NOTE]
26
30
> 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)**.
27
31
28
-
# [Azure CLI](#tab/azurecli)
32
+
###[Azure CLI](#tab/azurecli)
29
33
30
34
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`.
31
35
@@ -43,7 +47,7 @@ az functionapp config appsettings set --name <myFunctionApp> \
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`.
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.
64
68
65
69
To disable a function only in the staging slot:
66
70
67
-
# [Portal](#tab/portal)
71
+
###[Portal](#tab/portal)
68
72
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.
70
74
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.
72
76
73
-
# [Azure CLI](#tab/azurecli)
77
+
###[Azure CLI](#tab/azurecli)
74
78
75
79
```azurecli-interactive
76
80
az functionapp config appsettings set --name <FUNCTION_APP_NAME> \
@@ -85,7 +89,7 @@ az functionapp config appsettings set --name <myFunctionApp> \
Azure PowerShell currently doesn't support this functionality.
91
95
@@ -101,89 +105,28 @@ You can still cause a disabled function to run by supplying the [master key](fun
101
105
102
106
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).
103
107
104
-
## local.settings.json
108
+
## Disable functions locally
105
109
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:
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:
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
-
180
123
## Considerations
181
124
182
125
Keep the following considerations in mind when you disable functions:
183
126
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).
185
128
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.
0 commit comments