Question:
You are asked to create a function app in Azure where you want to have dedicated compute resources and you don't want the function app to be paused during periods of inactivity. How would you set up such an Azure function app using Azure CLI? Assume you are starting from scratch and you need to take care of any required setup or prerequisites in your CLI commands.
Answer:
Dedicated plan with "Always on" set.
# Variables
resourceGroupName="MyResourceGroup"
storageName="mystorageaccount"
planName="MyAppServicePlan"
functionAppName="myfunctionappservice"
location="westus2"
# Create a resource group
az group create --name $resourceGroupName --location $location
# Create an Azure Storage Account
az storage account create --name $storageName --location $location --resource-group $resourceGroupName --sku Standard_LRS
# Create an App Service plan
az appservice plan create --name $planName --resource-group $resourceGroupName --location $location --sku S1
# Create a function app with the App Service plan
az functionapp create --resource-group $resourceGroupName --plan $planName --name $functionAppName --storage-account $storageName --runtime node --functions-version 3
# Set the function app to always be on
az functionapp config set --name $functionAppName --resource-group $resourceGroupName --always-on true