Create a function app for serverless code execution

This Azure Functions sample script creates a function app, which is a container for your functions. The function app is created using the consumption plan, which is ideal for event-driven serverless workloads.

The function app created by this script uses version 1.x of the Azure Functions runtime. To learn how to upgrade to version 2.x, which is in preview, see Target a version using Azure CLI.

If you don't have an Azure subscription, create a free account before you begin.

Open Azure Cloud Shell

Azure Cloud Shell is a free, interactive shell that you can use to run the steps in this article. Common Azure tools are preinstalled and configured in Cloud Shell for you to use with your account. Just select the Copy button to copy the code, paste it in Cloud Shell, and then press Enter to run it. There are a few ways to open Cloud Shell:

Select Try It in the upper-right corner of a code block. Cloud Shell in this article
Open Cloud Shell in your browser. https://shell.azure.com/bash
Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Cloud Shell in the portal

If you choose to install and use the CLI locally, this article requires that you are running the Azure CLI version 2.0 or later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0.

Sample script

This script creates an Azure Function app using the consumption plan.

#!/bin/bash

# Function app and storage account names must be unique.
storageName=mystorageaccount$RANDOM
functionAppName=myserverlessfunc$RANDOM

# Create a resource group.
az group create --name myResourceGroup --location westeurope

# Create an Azure storage account in the resource group.
az storage account create \
  --name $storageName \
  --location westeurope \
  --resource-group myResourceGroup \
  --sku Standard_LRS

# Create a serverless function app in the resource group.
az functionapp create \
  --name $functionAppName \
  --storage-account $storageName \
  --consumption-plan-location westeurope \
  --resource-group myResourceGroup
  

Clean up deployment

After the sample script has been run, the following command can be used to remove the resource group and all resources associated with it.

az group delete --name myResourceGroup

Script explanation

Each command in the table links to command specific documentation. This script uses the following commands:

Command Notes
az group create Creates a resource group in which all resources are stored.
az storage account create Creates an Azure Storage account.
az functionapp create Creates a function app.

Next steps

For more information on the Azure CLI, see Azure CLI documentation.

Additional Azure Functions CLI script samples can be found in the Azure Functions documentation.