Simultaneously deploy multiple functions in a single Azure function app

 In this article, I will explain a method I used while working with multiple functions to manage multiple azure functions under an azure function app.

Issue with VSCode: In Visual Studio Code, each time I create a python function, it will add a new project directory along with a separate virtual environment, host.json and other config files. When I try to deploy a function it will delete existing azure functions in the function app.

Resolution: With Azure CLI, using 'func' command, multiple python functions are created with common virtual environment, requirements.txt, host.json and local.settings.json. Deploying from the parent directory will make sure all functions are deployed and are in the latest versions.

Detailed Explanation:

Starting with the basics, open command prompt/terminal/powershell and login to Azure CLI (Command: az login). A new tab will be opened in your browser and ask for login info. After successful login, you will be redirected to terminal and window will look as below,

az login debian

Now, check if func is available on your machine. Else follow azure cli tools tutorial which involves node.js and npm installation. Use command func  - -version for verification. Refer the screenshot below,

func --version

Creating the function app/project which holds multiple azure functions. Command to create the app/project is func init <app-name> --<language> 

func init command linux

After above step, we have a local python azure function project called funcproject. If you look into the contents, there is a host.json, local.settings.json, requirements.txt applicable for all the upcoming function apps.

Now, go ahead and create two function apps with http trigger called httpexample1, httpexample2 using command func new --name <function-name> --template "HTTP trigger" --authlevel "anonymous".

func new command http trigger

Here we have two functions httpexample1, httpexample2 inside function app funcproject. Next step is to create function app in azure portal.
Follow below steps,
  • Login to azure portal @https://portal.azure.com.
  • Navigate to your subscription and create a resource group.
  • In the resource group create new resource - Function App.
  • Choose function app name, publish method as Code and select Python runtime stack. 
  • After completion go back to terminal.
Create function app from azure portal

In terminal, use azure publish command to deploy the app to newly created azure function app resource. Refer below screenshot.


Deploy azure function from command line
..............................
azure function deploy from terminal

So, we have successfully deployed two http triggered functions simultaneously. Also, check the azure portal and test a function with GET request for confirmation. Please refer below screenshots.

Azure portal function app home


Azure function GET trigger example.
If you face any issue with this tutorial please let me know in comment section. Thank You!

Comments

Popular posts from this blog

The beginning of Data Quest

Automate Blog Post creation using Blogger APIs and Python

How to install Ubuntu Server and set up static IP (WiFi) on Raspberry Pi 3

Setting up Python Flask server on internet via Port forwarding

Creation of Orphan Process in Linux using Python