question

ShervinMirsaeidi-4877 avatar image
0 Votes"
ShervinMirsaeidi-4877 asked ShervinMirsaeidi-4877 commented

Disable Python Azure Function Using Hosted on Consuption Function App

Hi Team,

I have been trying to disable/enable Python Azure Function hosted on Consumption Function App but I have had no success. However I was able to disable/enable a C# Azure Function on Consumption plan. I have tried both methods suggested by this answer from the following Microsoft thread :

(https://docs.microsoft.com/en-us/answers/questions/396131/creating-a-azure-python-or-c-function-dynamically.html?childToView=420716#comment-420716)

First I tried to set the attribute "isDisabled" to "true" when I create the function using the Create Azure Function Rest API from the following documentation :

(https://docs.microsoft.com/en-us/rest/api/appservice/web-apps/create-function)

Second I have tried to use the below endpoint to enable and disable a particular function.

https://management.azure.com/subscriptions/{subscriptionID}/resourceGroups/{resourcegroupname}/providers/Microsoft.Web/sites/{sitename}/functions/{functionappname}/properties/state?api-version=2018-11-01

Request Body:

{"properties":"disabled"}
OR
{"properties":"enabled"}

Both approaches do not work for Python function hosted on Consumption plan. But for C# only the second solution works. When I send the REST PUT request for the Python function hosted on Consumption plan I get a "bad request 400" response with the following error



{
"Code":"BadRequest",
"Message":"AppSetting with name 'AzureWebJobs.<my function name>.Disabled' is not allowed.",
"Target":null,
"Details":[
{
"Message":"AppSetting with name 'AzureWebJobs.<my function name>.Disabled' is not allowed."
},
{
"Code":"BadRequest"
},
{
"ErrorEntity":{
"ExtendedCode":"04072",
"MessageTemplate":"AppSetting with name '{0}' is not allowed.",
"Parameters":[
"AzureWebJobs.<my function name>.Disabled"
],
"Code":"BadRequest",
"Message":"AppSetting with name 'AzureWebJobs.<my function name>.Disabled' is not allowed."
}
}
],
"Innererror":null
}




Can you please let me know if you notice the same issue on your end? Also if there is anyway I can programmatically disable a Python Azure Function hosted on Consumption Function App using REST API? perhaps I need to get the higher tier for Python functions?

Thanks for your time

azure-functions
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.

1 Answer

PramodValavala-MSFT avatar image
1 Vote"
PramodValavala-MSFT answered ShervinMirsaeidi-4877 commented

@ShervinMirsaeidi-4877 The REST API (the same used by the button in UI) works by setting an app setting as mentioned in the docs.

Based on the error that you've shared, I would guess there is an invalid character, likely a - (hyphen) which isn't valid on Linux.



· 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.

@PramodValavala-MSFT

Yes you are correct. The issue was I was using a Guid generator to create the function name. Once I removed the - (hyphen) from the generated name I worked as expected for both Python and C# Azure Functions.

Thanks again for your help

0 Votes 0 ·