Introduction
We can create Azure function apps using Code, Azure Portal or Azure CLI. In this post, we will see how to create an Azure function App using Azure CLI commands(az functionapp create). The Azure CLI can be launched from Azure Portal(cloud shell icon on top) or using https://shell.azure.com/ or you can install Azure CLI locally.
Create Resource Group
Below command creates a resource group(rgdnmfncli) in centralindia region.
rgname=rgdnmfncli
region=centralindia
az group create --name $rgname --location $region
In the CLI command, $rgname and $region are variables which are re-used in other commands. Once the resource group is created, you will get a Succeeded message.
Create Azure Storage Account
Storage account is mandatory to create a Function App. Below command creates storage account named (dnmsaxxxx)in centralindia region under resource group(rgdnmfncli).
storageName=dnmsa$RANDOM
az storage account create --name $storageName --location $region --resource-group $rgname --sku Standard_LRS
In the CLI command, $storageName is the variable which can be re-used in other commands. Azure function and storage account names has to be unique so we have added $RANDOM. $RANDOM is an internal bash function which generates and appends 4 digit numbers to storage account name(dnmsa).
Once the storage account is created, you will get a finished response.
Create a Function App
Below command creates a function app named (dnmhelloworldxxxx)in centralindia region under resource group(rgdnmfncli) with storage account mapping. Also we used Function Runtime 3.0 version.
functionappname=dnmhelloworld$RANDOM
az functionapp create --name $functionappname --storage-account $storageName --consumption-plan-location $region --resource-group $rgname --functions-version 3
Once the Function App is created, you will get a finished response. Also, you will get a message like “dnmhelloworld7233” app insights created for this function app with all Function App properties.
Fig: Azure Function App created - using CLI commands
Delete Resource Group
Below command deletes the created resource group(rgdnmfncli) to clean up all your resources under the resource group.
rgname=rgdnmfncli
az group delete --name $rgname
It asks “Are you sure you want to perform this operation? (y/n) - type y and press enter and after some time it deletes all your resources including the resource group.
References