Edit Azure function (Python) in VS code - python

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~

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

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.

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

How to deploy AWS python Lambda project locally?

I got an AWS python Lambda function which contains few python files and also several dependencies.
The app is build using Chalice so by that the function will be mapped like any REST function.
Before the deployment in prod env, I want to test it locally, so I need to pack all this project (python files and dependencies), I tried to look over the web for the desired solution but I couldn't find it.
I managed to figrue how to deploy one python file, but a whole project did not succeed.
Take a look to the Atlassian's Localstack: https://github.com/atlassian/localstack
It's a full copy of the AWS cloud stack, locally.
I use Travis : I hooked it to my master branch in git, so that when I push on this branch, Travis tests my lambda, with a script that uses pytest, after having installed all its dependencies with pip install. If all the tests passed, it then deploy the lambda in AWS in my prod-env.

Run custom Python script before appcfg.py update runs

Is that possible to run some Python script every time I run deployment process with appcfg.py? I need that to copy some files from external source to my app folder before uploading it to GAE. Thanks!
I checked briefly the sources of appcfg.py, the script that deploys the application to Google App Engine, but I didn't find a place where a pre-deploy hook can be defined.
I believe that modifying appcfg.py itself would me not mantainable and a bit overkill.
You should create a simple deployment script and call your command from the script.
For example, you can create a simple Makefile with only one target that does what you want:
deploy:
your-copy-command
/path/to/gae-devkit/appcfg.py update .
Running the make command will execute the command to copy external files and call the Google App Engine deployment tool.

Categories