Enable or disable your Azure Functions programmatically
Tags: azure, serverless, cloud
Published: 2020-05-26 18:31:04

---
title: Enable or disable your Azure Functions programmatically
published: true
description: You don't have to enable or disable the whole Function App at once. You can do it more granularily.
tags: azure, serverless, cloud 
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/1a9vvoxiopgnfegx9mxn.jpg
---

You probably already know that an Azure Function App can be comprised of multiple Azure Functions, and you probably know that you can disable either your whole Function App or, in a more granular manner, each Azure Functions independently.
You can do this from the Azure Portal, like this:

![](https://dev-to-uploads.s3.amazonaws.com/i/tvi97u99gvi1gdlp97ck.gif)

But you can also do it using an app setting. This is the approach we'll explore together today.


# Why would I do that?
You may want to disable a subset of your functions for many reasons:
* a given function is not behaving as expected, thus you'd want to disable temporarily;
* you have some "validation" function that you don't want to enable by default but rather enable it when needed;
* you want to deprecate a given function, so you can disable it and have the flexibility to re-enable it if needed for a given period of time before removing it for good.

Having the ability to enable or disable your functions programmatically gives you the flexibility to do it at different stages:
* in your CI/CD pipeline before the function is deployed;
* using Azure CLI or Azure PowerShell after the function has been deployed.


# How would I do that?
Let's consider we have an Azure Function App with 2 functions: **SayHello** and **SayGoodbye** and that we want to disable the **SayGoodbye** function.

We would go to the **Configuration** tab of our Function App and add a new boolean app setting named using this pattern: 

```
AzureWebJobs.<name-of-the-function-to-disable>.Disabled
```

In our case, it will be **AzureWebJobs.SayGoodbye.Disabled** and assign it the value **true**.

When we'd want to re-enable that function, we simply set the value of that app setting to **false** or we can also remove the app setting.

Want to see it in action? There you go:

![](https://dev-to-uploads.s3.amazonaws.com/i/vt98vz87y9h24qf866ck.gif)

Now, if you try to invoke the disabled function, you'll get an HTTP 404 error:

![](https://dev-to-uploads.s3.amazonaws.com/i/b1z4grow5ayk6au7bb7u.png)


## "How is this _Programmatically_?"
I'm hearing you from here :)
It is as you can do it either with PowerShell or Azure CLI or even right in your ARM Template. 

Here's how you could do this in the _parameters_ file of your ARM Template:

``` json
"appSettings": {
      "value": [
        //...,
        {
          "name": "AzureWebJobs.SayGoodbye.Disabled",
          "value": "true"
        },
        //...
      ]
}
``` 

# As a conclusion…
Today, we've seen how we can easily enable or disable some subset of our Azure functions, why we would want to do that and how do we achieve it.

I hope that you found it valuable. 

# Keep the discussion
You can reach me on [Twitter](https://twitter.com/tidjani_b) or [LinkedIn](https://ca.linkedin.com/in/tidjani-belmansour-ph-d-98460912).

See you soon!