在進階方案中建立函式應用程式 - Azure CLICreate a function app in a Premium plan - Azure CLI

這個 Azure Functions 範例指令碼會建立函式應用程式,這是您的函式容器。This Azure Functions sample script creates a function app, which is a container for your functions. 所建立的函式應用程式會使用可調整的進階方案The function app that is created uses a scalable Premium plan.

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶If you don't have an Azure subscription, create a free account before you begin.

必要條件Prerequisites

  • Azure Cloud Shell中使用 Bash 環境。Use the Bash environment in Azure Cloud Shell.

    在新視窗中啟動 Cloud ShellLaunch Cloud Shell in a new window

  • 如果想要,請安裝 Azure CLI 以執行 CLI 參考命令。If you prefer, install the Azure CLI to run CLI reference commands.

    • 如果您使用的是本機安裝,請使用 az login 命令,透過 Azure CLI 來登入。If you're using a local installation, sign in to the Azure CLI by using the az login command. 請遵循您終端機上顯示的步驟,完成驗證程序。To finish the authentication process, follow the steps displayed in your terminal. 如需其他登入選項,請參閱使用 Azure CLI 登入For additional sign-in options, see Sign in with the Azure CLI.

    • 出現提示時,請在第一次使用時安裝 Azure CLI 擴充功能。When you're prompted, install Azure CLI extensions on first use. 如需擴充功能詳細資訊,請參閱使用 Azure CLI 擴充功能For more information about extensions, see Use extensions with the Azure CLI.

    • 執行 az version 以尋找已安裝的版本和相依程式庫。Run az version to find the version and dependent libraries that are installed. 若要升級至最新版本,請執行 az upgradeTo upgrade to the latest version, run az upgrade.

  • 本教學課程需要 2.0 版或更新版本的 Azure CLI。This tutorial requires version 2.0 or later of the Azure CLI. 如果您是使用 Azure Cloud Shell,就已安裝最新版本。If using Azure Cloud Shell, the latest version is already installed.

範例指令碼Sample script

此指令碼會使用進階方案建立函式應用程式。This script creates a function app using a Premium plan.

#!/bin/bash

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

# Create a resource resourceGroupName
az group create \
  --name myResourceGroup \
  --location $region

# Create an azure storage account
az storage account create \
  --name $storageName \
  --location $region \
  --resource-group myResourceGroup \
  --sku Standard_LRS

# Create a Premium plan
az functionapp plan create \
  --name mypremiumplan \
  --resource-group myResourceGroup \
  --location $region \
  --sku EP1

# Create a Function App
az functionapp create \
  --name $functionAppName \
  --storage-account $storageName \
  --plan mypremiumplan \
  --resource-group myResourceGroup \
  --functions-version 2
  

清除部署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:

CommandCommand 注意Notes
az group createaz group create 建立用來存放所有資源的資源群組。Creates a resource group in which all resources are stored.
az storage account createaz storage account create 建立 Azure 儲存體帳戶。Creates an Azure Storage account.
az functionapp plan createaz functionapp plan create 特定 SKU 中建立進階方案。Creates a Premium plan in a specific SKU.
az functionapp createaz functionapp create 在 App Service 方案中建立函式應用程式。Creates a function app in the App Service plan.

後續步驟Next steps

如需 Azure CLI 的詳細資訊,請參閱 Azure CLI 文件For more information on the Azure CLI, see Azure CLI documentation.

您可以在 Azure Functions 文件中找到其他 Azure Functions CLI 指令碼範例。Additional Azure Functions CLI script samples can be found in the Azure Functions documentation.