Azure Functions in VS Code - python

I am trying to run my Python code with Azure Functions using Visual Studio Code. I have run the "Hello World" project with Azure Functions in VS Code, but I am looking for a way to deploy my Python code with Azure Functions. I would really appreciate it if anyone can help me with this issue by introducing a relevant tutorial or sharing some ideas.

This is Azure for Python Developers
and you want to deploy python code to azure, there are three options for you to choose with regard to different code situation:
Deploy a web app with VS Code
Deploy Docker containers to Azure App Service with Visual Studio Code
Create and deploy serverless Azure Functions in Python with Visual Studio Code

First, you need to create a function app on azure. This is a container to deploy your function.
Then you have two ways to deploy:
1, use VS code:
click the upload button, and then select the folder you want to deploy, the subscription, and select the function app you created just now.
2, use cmd:
Go to the root folder of your function, and run this command:
func azure functionapp publish <FunctionAppName>
The name of function app is absolutely unique, so if you have the authority then your folder will deploy to this function app directly.

Related

How to set java home in azure function app with python run time?

I have python run time in azure function app. I have added install-jdk in requirements.txt. I would like to find the JAVA_HOME and set it in azure function. Thanks

How to host Azure Python API via Azure Data Storage

I have python scripts that I want to host as a web app in azure.
I want to keep the function scripts in azure data storage and host them as a python API in azure.
I want some devs to be able to change the scripts in the azure data storage and reflect the changes live without having to deploy.
How can I got about doing this?
Create Function App of Runtime Stack Python supported only in Linux Version in any Hosting Plan through Azure Portal.
Make the Continuous Deployment setting to GitHub under Deployment Center of the function app in the portal like below:
After authorizing, provide your GitHub Repository details in the same section.
Create the Azure Python Functions from VS Code and deploy to the GitHub Repository using Git Clone through Command Palette.
After that, you can deploy the functions to azure function app.
Here after publishing to azure, you'll get the Azure Functions Python Rest API.
I want some devs to be able to change the scripts in the azure data storage and reflect the changes live without having to deploy.
Whenever you or dev's make changes the changes in code through GitHub and commit the changes, then it automatically reflects in the Azure Portal Function App.
For more information, please refer this article and GitHub actions of editing the code/script files.

File version different between Azure Portal and Azure Portal Kudu for the same file

Currently my Azure Function shows a different file version in the portal as compared to Kudu.
I am using Azure App Service /w Azure Functions V2 and Python 3.7.
I publish my function app using:
func azure functionapp publish <functionappname>
It successfully performs a remote build.
Now if I look at my Function App in the portal I can see the updated version of my init.py. However, when I use Kudu (Platform features > Advanced tools (Kudu)) to look into the file /home/site/wwwroot//init.py I still see the old version. Shouldn't these versions be identical?
I hope some experienced user can shed light on this.
I test it in my side, when I create a new azure function app(python) and deploy the python code from VS Code to azure portal. It will not create a "init.py" under the directory /home/site/wwwroot. In this directory, it just exists a "host.json"(shown as below).
So you can see the new version of your "init.py" after your deployment on azure portal, but it seems the old version "init.py" in the directory /home/site/wwwroot may be created by a deployment in the past or created because some other reasons in the past. I think it has nothing to do with your new deployment.

Edit Azure function (Python) in VS code

I'm new to using Azure function apps and need to publish an updated init.py file to an existing function app.
Since Download app content is missing and I'll need to recreate it locally, what is normally contained in this file?
Is it possible to make sure all of the original settings remain the same and only update the init.py file?
For this requirement, I think you just need to copy the init.py code from azure to your new function in local VS code and copy the function.json from azure to local VS code.
In the new function you created in VS code, you need to use the init.py code and function.json copied above. And you need to run the command pip freeze > requirements.txt in "TERMINAL" in VS code to generate a requirements.txt which contains all of the pip modules used in your new function.
Then you can deploy it from VS code to Azure, the init.py(local) will cover the init.py in Azure and the function.json(local) will also cover the function.json in Azure. The new function in Azure will rebuild(install the pip modules) according to the requirements.txt you generated just now.
You can run this command in "TERMINAL" in VS code to deploy your new function from local to azure.
func azure functionapp publish hurypyfunapp --build remote
The new function you deployed from local to azure will not affect other settings such as "Application settings" and so on.
By the way, before the deployment, you can test your function locally by running the command below in "TERMINAL" in VS code to start your function.
func host start
Hope it helps~

Is it able to create an HTTP triggered python function on Azure Function without doing any local coding?

I wonder is it able to create an HTTP triggered python function on Azure Function without doing any local coding? I want to do everything on Azure cloud. My python function codes are in a Github/Azure repos repository, but I do not have all the extra files of an Azure function project (for example, a init.py script file that is the HTTP trigger function of the Azure Function App). Is it possible to generate those files from Azure (without generating any Azure Function related files on my local computer)? I noticed that we cannot do in-portal editing for Python function Apps.
As far as I know, we can just deploy the python function from local to Azure cloud, but can not deploy it as you expected. And I think it will not be too difficult to us to deploy the python function from local to azure cloud.
Since you have had the main python function code "init.py", you just need to sign in to Azure in you VS code and create python function by following this tutorial. And then use your init.py code to replace the new python function code. After that, run the command below in "TERMINAL" window to generate the "requirements.txt":
pip freeze > requirements.txt
The "requirements.txt" includes all of the modules which imported in your "init.py" and when the function deployed to azure, azure will install these modules by this "requirements.txt". I saw you mentioned you don't have all the extra files of this function project, if these modules are what you care about, the "requirements.txt" will solve your problem.
Then use this command to deploy it to Azure:
func azure functionapp publish hurypyfunapp --build remote

Categories