question

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

Creating Azure Python Function App Hosted on Consuption Plan Using ARM Template

Hi team,

I been looking at the following post on this form :

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

and its mentioned in there how to create a Azure Python Function App on the Consumption hosting plan. It says to define WEBSITE_CONTENTAZUREFILECONNECTIONSTRING, WEBSITE_CONTENTSHARE app settings. But looking at this following documentation :

(https://docs.microsoft.com/en-us/azure/azure-functions/functions-infrastructure-as-code)

It says WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE are not supported for Linux machine. When I try to create a Python Azure Function App from the portal it says only Linux machine is allowed for Python. Is the documentation I posted above outdated or changed?

Can you please provide me direction? What I'm trying to do is create a Azure Python Function App using a ARM template using the REST API. I am using the following documentation:

(https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-rest)

Assuming I'm deploying to already created resource group with nothing in it. I have found a quick start template for creating a Node Function App on Consumption hosting plan using the following documentation :

(https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.web/function-app-create-dynamic)

Can you please share similar ARM template for creating Azure Python Function App on Consumption hosting plan similar to documentation above or perhaps guide me to the right direction

Thank you 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.

MayankBargali-MSFT avatar image
1 Vote"
MayankBargali-MSFT answered MayankBargali-MSFT edited

@ShervinMirsaeidi-4877 This statement is correct "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE are not supported for Linux machine". You can refer to function app setting document and it says the same for WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE

Yes, python function are only supported in Linux OS. The same is mentioned in our function reference python document.
102238-image.png

You can refer to this document for operating system and language runtime support for the hosting plans.

You can use the same ARM template and customize it according to your needs. For creating python function you need to pass the runtime value as python. You can find the valid values as mentioned in this document. Please refer to different properties for Microsoft.Web/sites. I have removed the WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE from the appSettings property. For linux ARM template updated the same as mentioned in Linux section and removed the "Microsoft.Web/serverfarms" section and dependencies.

102216-image.png

Attaching the ARM template for your reference.


image.png (16.4 KiB)
image.png (6.6 KiB)
arm-template.txt (3.5 KiB)
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.

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

@MayankBargali-MSFT

Thank you for your response. That is exactly what I was looking for. However seems like after creating all the resources by running the ARM template were having the same issue we had in the other form, where without the WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE inside the siteConfig any newly created Python Function disappears after few seconds and when I try to run it I get a 404 not found error, and after couple mins the function disappears. Same as the screen shots I posted in the form :
(https://docs.microsoft.com/en-us/answers/questions/396131/creating-a-azure-python-or-c-function-dynamically.html?childToView=407137#comment-407137)

I have tried the same ARM template you provided and I have added WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE to the siteConfig and it works now. Even though the documentation says you cannot add these for Linux machine. I have attached my ARM template to this message incase someone else needs it. Please let me know if you noticed the same thing on your end? 102496-pythonfunctionappconsumptionhostedarmtemplate.txt



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

@ShervinMirsaeidi-4877 When you mentioned it disappears. Are you using REST API to create the azure function. Using the ARM it creates the function app without any function. I tried to deploy the function in my function app using visual studio/VS code but couldn't observe any issue. Similarly I deployed the simple python function and it deployed successfully as mentioned in our previous discussion. Complex function dynamically with dependencies not loading correctly using REST API would caused the issue. Dynamically creating the function using REST API is not the recommended approach for performance reasons.
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE are just the configuration value but if you want you can still define them but are never used in Linux OS.

1 Vote 1 ·

@MayankBargali-MSFT

Yes for creating azure functions I'm using REST API. The reason is we need to create it dynamically. So we let user chose timer or HTTP and we create the template for the Azure function and place the users code inside the template. This means the user does not have access to VS code or any other IDE. They will use a website that we created to enter C# or Python code that will run against the custom API that I have created. So I wont need any special libraries. All I need is the already build in HTTP client to send and receive data from the function to the back end I have created. I can see that we can use ARM template to create function but I dont see how we can put the code inside the body. It looks like its pointing to link for its "script_href", so that options would not work.

I'm guessing this is the only option I have to achieve what I have explained above?

Thanks again

0 Votes 0 ·
ShervinMirsaeidi-4877 avatar image
0 Votes"
ShervinMirsaeidi-4877 answered ShervinMirsaeidi-4877 commented

@MayankBargali-MSFT

The only way I can create a python azure function via REST API hosted on a consumption plan is to have the WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE set under my site configuration or else the function disappears after few seconds. I have created and executed the HTTP trigger Python Azure function on consumption plan successfully with this mentioned configuration. However, I have been trying to create a Timer Python Azure Function via REST API but I have had no luck. I have successfully created and deployed a Timer Python Azure function using visual studio code and after creation, I called the GET Function REST API to get a idea of what attributes are required in the REST API body. But when I create the function via REST API it creates successfully and when it runs it throws the error


"Result: Failure Exception: FunctionLoadError: cannot load the myTimer function: the following parameters are declared in Python but not in function.json: {'mytimer'} Stack: File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 308, in handle_function_load_request function_id, func, func_request.metadata) File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/functions.py", line 114, in add_function 'the following parameters are declared in Python but '"


I have attached the payload I used in my REST API request to this message. Please let me know if I'm missing something?

Thanks again for your time

104810-requestbody.txt




requestbody.txt (560 B)
· 2
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.

@ShervinMirsaeidi-4877 As per the error message you have define the binding name as "myTimer" whereas your init.py have the name "mytimer". There is casing issue 't' with the binding name and that you have define in your python program. I came across Azure function core tools that have templates.json file which has template for different trigger for different languages. You can find the same under "C:\Users{user}.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle{version}\StaticContent\v1\templates\templates.json" that will help you a lot with the request body creation. Attaching the same for your reference.

1 Vote 1 ·
templates.txt (137.2 KiB)

Thank you so much its working now. Also documentation is very helpful. Appreciate it

0 Votes 0 ·