Deploy Azure function using Azure CLI

The Azure command-line interface (Azure CLI) is a set of commands used to create and manage Azure resources. It is available across Azure services and is designed to get you working quickly with Azure, with an emphasis on automation. You can check how to install and configure Azure CLI in you machine from here.

This article describes how to deploy your function app to Azure using AWS CLI commands. For deploying the azure fuction you need to first create a zip file with the contents of your azure function. The .zip file that you use for push deployment must contain all of the files needed to run your function. When you deploy it, the contents of the zip file will be extracted and copied to the wwwroot folder of your function app(If any files from an existing deployment that aren't found in the .zip file are deleted from your function app). The folder structure of your zip file should be as below

FunctionApp
 | - host.json
 | - MyFirstFunction
 | | - function.json
 | - MySecondFunction
 | | - function.json
 | - SharedCode
 | - bin


The code for all the functions in a specific function app is located in a root project folder that contains a host configuration file and one or more sub folders. Each sub folder contains the code for a separate function. The bin folder contains packages and other library files that the function app requires. 

 So for deploying your azure function app, you need to publish your app first in Visual Studio using folder publish. Once done, zip the publish folder and run the following command in command line

az functionapp deployment source config-zip -g  -n  --src 

Ex:
az functionapp deployment source config-zip -g "rg-test-group" -n "func-test-function" --src "D:\test-function\bin\Release\netcoreapp2.1\publish\publish.zip"

This command deploys project files from the .zip file to your function app and restarts it. Here is the path of your zip file on your computer. If you are using Azure CLI in Azure Cloud Shell, then you must upload your file to the Azure files account.

Happy Coding 😊!

Gopikrishna

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment