loading...
Cover image for Enable or disable your Azure Functions programmatically

Enable or disable your Azure Functions programmatically

tidjani profile image Tidjani Belmansour, Ph.D. ・2 min read

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:

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:

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

"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:

"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 or LinkedIn.

See you soon!

Posted on Jun 19 by:

tidjani profile

Tidjani Belmansour, Ph.D.

@tidjani

Hi, my name is Tidjani Belmansour. I'm a Microsoft Azure MVP, a Cloud Solutions Architect and a coffee addict. I've been in love with computers since 1988.

Discussion

markdown guide
 

Thanks for the tip. This is much nicer than having to use the portal or Azure Cli.

 

great that you liked it, Kane! :)