0
0
Azurecloud~5 mins

Function App creation in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Creating a Function App lets you run small pieces of code in the cloud without managing servers. It solves the problem of running code that responds to events quickly and scales automatically.
When you want to run code that reacts to changes in data or messages without setting up a server.
When you need to run background tasks like sending emails or processing files automatically.
When you want to build APIs that scale easily without managing infrastructure.
When you want to save costs by paying only for the time your code runs.
When you want to connect different cloud services with simple code triggered by events.
Config File - functionapp.json
functionapp.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2022-03-01",
      "name": "example-functionapp",
      "location": "eastus",
      "kind": "functionapp",
      "properties": {
        "serverFarmId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/serverfarms/example-plan",
        "siteConfig": {
          "appSettings": [
            { "name": "FUNCTIONS_EXTENSION_VERSION", "value": "~4" },
            { "name": "FUNCTIONS_WORKER_RUNTIME", "value": "dotnet" }
          ]
        }
      }
    }
  ]
}

This JSON is an Azure Resource Manager template to create a Function App named example-functionapp in the eastus region.

The serverFarmId links to an App Service plan that hosts the Function App.

App settings specify the runtime version and language.

Commands
Create a resource group named example-rg in the eastus region to hold your Function App and related resources.
Terminal
az group create --name example-rg --location eastus
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg", "location": "eastus", "managedBy": null, "name": "example-rg", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Sets the name of the resource group
--location - Sets the Azure region for the resource group
Create an App Service plan named example-plan in the example-rg group. This plan hosts the Function App and defines its compute resources.
Terminal
az appservice plan create --name example-plan --resource-group example-rg --sku B1 --is-linux false
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/serverfarms/example-plan", "location": "eastus", "name": "example-plan", "properties": { "status": "Ready", "workerTierName": null }, "sku": { "capacity": 1, "family": "B", "name": "B1", "size": "B1", "tier": "Basic" }, "type": "Microsoft.Web/serverfarms" }
--sku - Defines the pricing tier and size of the plan
--is-linux - Specifies the OS; false means Windows
Create the Function App named example-functionapp using the storage account examplestorageacct, in the example-rg group, hosted on example-plan, using .NET runtime version 4.
Terminal
az functionapp create --name example-functionapp --storage-account examplestorageacct --resource-group example-rg --plan example-plan --runtime dotnet --functions-version 4
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/sites/example-functionapp", "location": "eastus", "name": "example-functionapp", "state": "Running", "type": "Microsoft.Web/sites" }
--storage-account - Specifies the Azure Storage account for the Function App
--runtime - Sets the language runtime for the Function App
--functions-version - Sets the version of Azure Functions runtime
Check the details and status of the Function App to confirm it was created and is running.
Terminal
az functionapp show --name example-functionapp --resource-group example-rg
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/sites/example-functionapp", "location": "eastus", "name": "example-functionapp", "state": "Running", "type": "Microsoft.Web/sites" }
Key Concept

If you remember nothing else from this pattern, remember: a Function App runs your code in the cloud without servers, triggered by events, and needs a resource group, hosting plan, and storage to work.

Common Mistakes
Not creating a storage account before creating the Function App
Function Apps require a storage account to store code and state; without it, creation fails.
Create an Azure Storage account first using 'az storage account create' and specify it during Function App creation.
Using an App Service plan SKU that does not support Function Apps
Some SKUs do not support running Function Apps or do not scale properly.
Use a supported SKU like B1 (Basic) or Consumption plan for hosting Function Apps.
Forgetting to specify the runtime and functions version
Azure needs to know which runtime and version to use to run your functions correctly.
Always include '--runtime' and '--functions-version' flags when creating the Function App.
Summary
Create a resource group to organize your Azure resources.
Create an App Service plan to host your Function App with defined compute resources.
Create the Function App specifying storage, runtime, and hosting plan.
Verify the Function App is running using the show command.