question

amirkhansinga-6399 avatar image
0 Votes"
amirkhansinga-6399 asked MayankBargali-MSFT answered

Enable/Disable functions in Azure programmically in C#

I've some azure functions that I want to disable/enable programmatically - e.g. by an http triggered function. Is there a way to do this directly in C# code of the function? I couldn't find anything like an api for that. Another option could be to use the app settings of the function app with a parameter like "FUNCTION1_ENABLED". With this, the function would not be really disabled but I can read this value on the beginning of the function and break it, if its false. But it looks like, that the app settings only can be set on startup of a function app - and not during runtime.

The final (but at least inelegant) solution would be to share a parameter stored in the database behind all functions - that can easily be set and read by any function.

But I hope, there is a way to disable/enable functions programmatically in C# by Azure itself.

azure-functions
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I don't think there is an api that just simply turn it of. There are some post out there exploring the use of KUDU: https://github.com/projectkudu/kudu/wiki/REST-API
same code here : https://stackoverflow.com/questions/42400963/how-to-enable-disable-azure-function-programmatically

0 Votes 0 ·

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered

@amirkhansinga-6399 Thanks for reaching out. To disable the function please refer to the disable function document.

Programmatically you can also use the below REST endpoint to enable/disable a particular function
PUT https://management.azure.com/subscriptions/{subscriptionID}/resourceGroups/{resourcegroupname}/providers/Microsoft.Web/sites/{sitename}/functions/{functionappname}/properties/state?api-version=2018-11-01
content-type: application/json; charset=utf-8

Request Body:

 {"properties":"disabled"}

OR

 {"properties":"enabled"}

Alternative you can also use this API to update app setting on your function app.

In case if you want to do it for your local environment then you can define below in your local.settings.json but when you deploy to azure then you need to define it in Application setting of your function app.

 "AzureWebJobs.yourfunctionname.Disabled": true

OR

 "AzureWebJobs.yourfunctionname.Disabled": 1

Feel free to get back to me if you need any assistance.

Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.