为 Azure Functions 中的函数应用自动执行资源部署Automate resource deployment for your function app in Azure Functions

可以使用 Azure 资源管理器模板来部署函数应用。You can use an Azure Resource Manager template to deploy a function app. 本文概述了完成此操作所需的资源和参数。This article outlines the required resources and parameters for doing so. 可能还需要部署其他资源,具体取决于函数应用中的触发器和绑定You might need to deploy additional resources, depending on the triggers and bindings in your function app.

有关创建模板的详细信息,请参阅创作 Azure 资源管理器模板For more information about creating templates, see Authoring Azure Resource Manager templates.

有关示例模板,请参阅:For sample templates, see:

所需资源Required resources

Azure Functions 部署通常包括以下资源:An Azure Functions deployment typically consists of these resources:

资源Resource 要求Requirement 语法和属性参考Syntax and properties reference
函数应用A function app 必选Required Microsoft.Web/sitesMicrosoft.Web/sites
Azure 存储帐户An Azure Storage account 必选Required Microsoft.Storage/storageAccountsMicrosoft.Storage/storageAccounts
Application Insights 组件An Application Insights component 可选Optional Microsoft.Insights/componentsMicrosoft.Insights/components
托管计划A hosting plan 可选1Optional1 Microsoft.Web/serverfarmsMicrosoft.Web/serverfarms

1只有选择在高级计划应用服务计划上运行函数应用时,托管计划才是必需的。1A hosting plan is only required when you choose to run your function app on a Premium plan or on an App Service plan.

提示

虽然不是必需的,但强烈建议为应用配置 Application Insights。While not required, it is strongly recommended that you configure Application Insights for your app.

存储帐户Storage account

函数应用需要 Azure 存储帐户。An Azure storage account is required for a function app. 你需要一个支持 blob、表、队列和文件的常规用途帐户。You need a general purpose account that supports blobs, tables, queues, and files. 有关详细信息,请参阅 Azure Functions 存储帐户要求For more information, see Azure Functions storage account requirements.

{
    "type": "Microsoft.Storage/storageAccounts",
    "name": "[variables('storageAccountName')]",
    "apiVersion": "2019-06-01",
    "location": "[resourceGroup().location]",
    "kind": "StorageV2",
    "sku": {
        "name": "[parameters('storageAccountType')]"
    }
}

此外,在站点配置中,必须将属性 AzureWebJobsStorage 指定为应用设置。In addition, the property AzureWebJobsStorage must be specified as an app setting in the site configuration. 如果函数应用未使用 Application Insights 进行监视,还应将 AzureWebJobsDashboard 指定为应用设置。If the function app doesn't use Application Insights for monitoring, it should also specify AzureWebJobsDashboard as an app setting.

Azure Functions 运行时使用 AzureWebJobsStorage 连接字符串创建内部队列。The Azure Functions runtime uses the AzureWebJobsStorage connection string to create internal queues. 未启用 Application Insights 时,运行时使用 AzureWebJobsDashboard 连接字符串登录到 Azure 表存储并启动门户中的“监视”选项卡。When Application Insights is not enabled, the runtime uses the AzureWebJobsDashboard connection string to log to Azure Table storage and power the Monitor tab in the portal.

这些属性在 siteConfig 对象中的 appSettings 集合中指定:These properties are specified in the appSettings collection in the siteConfig object:

"appSettings": [
    {
        "name": "AzureWebJobsStorage",
        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
    },
    {
        "name": "AzureWebJobsDashboard",
        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
    }
]

Application InsightsApplication Insights

建议使用 Application Insights 监视函数应用。Application Insights is recommended for monitoring your function apps. 使用类型“Microsoft.Insights/components”和种类“web”定义 Application Insights 资源:The Application Insights resource is defined with the type Microsoft.Insights/components and the kind web:

        {
            "apiVersion": "2015-05-01",
            "name": "[variables('appInsightsName')]",
            "type": "Microsoft.Insights/components",
            "kind": "web",
            "location": "[resourceGroup().location]",
            "tags": {
                "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('functionAppName'))]": "Resource"
            },
            "properties": {
                "Application_Type": "web",
                "ApplicationId": "[variables('appInsightsName')]"
            }
        },

此外,需要使用 APPINSIGHTS_INSTRUMENTATIONKEY 应用程序设置向函数应用提供检测密钥。In addition, the instrumentation key needs to be provided to the function app using the APPINSIGHTS_INSTRUMENTATIONKEY application setting. 此属性在 siteConfig 对象的 appSettings 集合中指定:This property is specified in the appSettings collection in the siteConfig object:

"appSettings": [
    {
        "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
        "value": "[reference(resourceId('microsoft.insights/components/', variables('appInsightsName')), '2015-05-01').InstrumentationKey]"
    }
]

托管计划Hosting plan

托管计划的定义是变化的,并且可能是下列项之一:The definition of the hosting plan varies, and can be one of the following:

函数应用Function app

函数应用资源是使用类型为 Microsoft.Web/sites 且种类为 functionapp 的资源定义的:The function app resource is defined by using a resource of type Microsoft.Web/sites and kind functionapp:

{
    "apiVersion": "2015-08-01",
    "type": "Microsoft.Web/sites",
    "name": "[variables('functionAppName')]",
    "location": "[resourceGroup().location]",
    "kind": "functionapp",
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
        "[resourceId('Microsoft.Insights/components', variables('appInsightsName'))]"
    ]
}

重要

如果你要显式定义托管计划,则 dependsOn 数组中可能将需要一个额外的项:"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"If you are explicitly defining a hosting plan, an additional item would be needed in the dependsOn array: "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"

函数应用必须包括以下应用程序设置:A function app must include these application settings:

设置名Setting name 说明Description 示例值Example values
AzureWebJobsStorageAzureWebJobsStorage Functions 运行时用于内部排队的存储帐户的连接字符串A connection string to a storage account that the Functions runtime uses for internal queueing 请参阅存储帐户See Storage account
FUNCTIONS_EXTENSION_VERSIONFUNCTIONS_EXTENSION_VERSION Azure Functions 运行时的版本The version of the Azure Functions runtime ~2
FUNCTIONS_WORKER_RUNTIMEFUNCTIONS_WORKER_RUNTIME 要为此应用中的函数使用的语言堆栈The language stack to be used for functions in this app dotnetnodejavapowershelldotnet, node, java, or powershell
WEBSITE_NODE_DEFAULT_VERSIONWEBSITE_NODE_DEFAULT_VERSION 只有当使用 node 语言堆栈时必需,指定要使用的版本Only needed if using the node language stack, specifies the version to use 10.14.1

这些属性是在 siteConfig 属性中的 appSettings 集合中指定的:These properties are specified in the appSettings collection in the siteConfig property:

"properties": {
    "siteConfig": {
        "appSettings": [
            {
                "name": "AzureWebJobsStorage",
                "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
            },
            {
                "name": "FUNCTIONS_WORKER_RUNTIME",
                "value": "node"
            },
            {
                "name": "WEBSITE_NODE_DEFAULT_VERSION",
                "value": "10.14.1"
            },
            {
                "name": "FUNCTIONS_EXTENSION_VERSION",
                "value": "~2"
            }
        ]
    }
}

在消耗计划上部署Deploy on Consumption plan

消耗计划会在代码运行时自动分配计算能力,根据需要增加分配以处理负载,然后在代码未运行时相应减少分配。The Consumption plan automatically allocates compute power when your code is running, scales out as necessary to handle load, and then scales in when code is not running. 你不需要为空闲的 VM 付费,也不需要提前保留容量。You don't have to pay for idle VMs, and you don't have to reserve capacity in advance. 若要了解更多信息,请参阅 Azure Functions 的缩放和托管To learn more, see Azure Functions scale and hosting.

有关 Azure 资源管理器模板示例,请参阅基于消耗计划的函数应用For a sample Azure Resource Manager template, see Function app on Consumption plan.

创建消耗计划Create a Consumption plan

不需要定义消耗计划。A Consumption plan does not need to be defined. 创建函数应用资源本身时,不会基于区域自动创建或选择消耗计划。One will automatically be created or selected on a per-region basis when you create the function app resource itself.

消耗计划是一种特殊的“serverfarm”资源。The Consumption plan is a special type of "serverfarm" resource. 对于 Windows,可以通过为 computeModesku 属性使用 Dynamic 值来指定它:For Windows, you can specify it by using the Dynamic value for the computeMode and sku properties:

{  
   "type":"Microsoft.Web/serverfarms",
   "apiVersion":"2016-09-01",
   "name":"[variables('hostingPlanName')]",
   "location":"[resourceGroup().location]",
   "properties":{  
      "name":"[variables('hostingPlanName')]",
      "computeMode":"Dynamic"
   },
   "sku":{  
      "name":"Y1",
      "tier":"Dynamic",
      "size":"Y1",
      "family":"Y",
      "capacity":0
   }
}

备注

不能显式为 Linux 定义消耗计划。The Consumption plan cannot be explicitly defined for Linux. 它将自动创建。It will be created automatically.

如果确实显式定义了消耗计划,则需要在应用上设置 serverFarmId 属性,使其指向计划的资源 ID。If you do explicitly define your Consumption plan, you will need to set the serverFarmId property on the app so that it points to the resource ID of the plan. 你还应当确保函数应用有一个针对该计划的 dependsOn 设置。You should ensure that the function app has a dependsOn setting for the plan as well.

创建函数应用Create a function app

WindowsWindows

在 Windows 上,消耗计划还需要站点配置中的两个附加设置:WEBSITE_CONTENTAZUREFILECONNECTIONSTRINGWEBSITE_CONTENTSHAREOn Windows, a Consumption plan requires two additional settings in the site configuration: WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE. 这些属性用于配置存储函数应用代码和配置的存储帐户和文件路径。These properties configure the storage account and file path where the function app code and configuration are stored.

{
    "apiVersion": "2016-03-01",
    "type": "Microsoft.Web/sites",
    "name": "[variables('functionAppName')]",
    "location": "[resourceGroup().location]",
    "kind": "functionapp",
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
    ],
    "properties": {
        "siteConfig": {
            "appSettings": [
                {
                    "name": "AzureWebJobsStorage",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
                },
                {
                    "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
                },
                {
                    "name": "WEBSITE_CONTENTSHARE",
                    "value": "[toLower(variables('functionAppName'))]"
                },
                {
                    "name": "FUNCTIONS_WORKER_RUNTIME",
                    "value": "node"
                },
                {
                    "name": "WEBSITE_NODE_DEFAULT_VERSION",
                    "value": "10.14.1"
                },
                {
                    "name": "FUNCTIONS_EXTENSION_VERSION",
                    "value": "~2"
                }
            ]
        }
    }
}

在高级计划上部署Deploy on Premium plan

高级计划提供与消耗计划相同的缩放,但包括专用资源和附加功能。The Premium plan offers the same scaling as the Consumption plan but includes dedicated resources and additional capabilities. 若要了解详细信息,请参阅 Azure Functions 高级计划To learn more, see Azure Functions Premium Plan.

创建高级计划Create a Premium plan

高级计划是特殊类型的“serverfarm”资源。A Premium plan is a special type of "serverfarm" resource. 可以通过使用 EP1EP2EP3 作为 sku 描述对象中的 Name 属性值来指定它。You can specify it by using either EP1, EP2, or EP3 for the Name property value in the sku description object.

{
    "type": "Microsoft.Web/serverfarms",
    "apiVersion": "2018-02-01",
    "name": "[parameters('hostingPlanName')]",
    "location": "[resourceGroup().location]",
    "properties": {
        "name": "[parameters('hostingPlanName')]",
        "workerSize": "[parameters('workerSize')]",
        "workerSizeId": "[parameters('workerSizeId')]",
        "numberOfWorkers": "[parameters('numberOfWorkers')]",
        "hostingEnvironment": "[parameters('hostingEnvironment')]",
        "maximumElasticWorkerCount": "20"
    },
    "sku": {
        "Tier": "ElasticPremium",
        "Name": "EP1"
    }
}

创建函数应用Create a function app

高级计划的函数应用必须将 serverFarmId 属性设置为之前创建的计划的资源 ID。A function app on a Premium plan must have the serverFarmId property set to the resource ID of the plan created earlier. 此外,高级计划还需要站点配置中的两个附加设置:WEBSITE_CONTENTAZUREFILECONNECTIONSTRINGWEBSITE_CONTENTSHAREIn addition, a Premium plan requires two additional settings in the site configuration: WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE. 这些属性用于配置存储函数应用代码和配置的存储帐户和文件路径。These properties configure the storage account and file path where the function app code and configuration are stored.

{
    "apiVersion": "2016-03-01",
    "type": "Microsoft.Web/sites",
    "name": "[variables('functionAppName')]",
    "location": "[resourceGroup().location]",
    "kind": "functionapp",            
    "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
    ],
    "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "siteConfig": {
            "appSettings": [
                {
                    "name": "AzureWebJobsStorage",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
                },
                {
                    "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
                },
                {
                    "name": "WEBSITE_CONTENTSHARE",
                    "value": "[toLower(variables('functionAppName'))]"
                },
                {
                    "name": "FUNCTIONS_WORKER_RUNTIME",
                    "value": "node"
                },
                {
                    "name": "WEBSITE_NODE_DEFAULT_VERSION",
                    "value": "10.14.1"
                },
                {
                    "name": "FUNCTIONS_EXTENSION_VERSION",
                    "value": "~2"
                }
            ]
        }
    }
}

在应用服务计划上部署Deploy on App Service plan

在应用服务计划中,函数应用在基本、标准和高级 SKU 中的专用 VM 上运行,类似于 Web 应用。In the App Service plan, your function app runs on dedicated VMs on Basic, Standard, and Premium SKUs, similar to web apps. 如需详细了解如何使用应用服务计划,请参阅 Azure 应用服务计划深入概述For details about how the App Service plan works, see the Azure App Service plans in-depth overview.

有关 Azure 资源管理器模板示例,请参阅基于 Azure 应用服务计划的函数应用For a sample Azure Resource Manager template, see Function app on Azure App Service plan.

创建应用服务计划Create an App Service plan

应用服务计划是由“serverfarm”资源定义的。An App Service plan is defined by a "serverfarm" resource.

{
    "type": "Microsoft.Web/serverfarms",
    "apiVersion": "2018-02-01",
    "name": "[variables('hostingPlanName')]",
    "location": "[resourceGroup().location]",
    "sku": {
        "name": "S1",
        "tier": "Standard",
        "size": "S1",
        "family": "S",
        "capacity": 1
    }
}

创建函数应用Create a function app

应用服务计划上的函数应用必须将 serverFarmId 属性设置为之前创建的计划的资源 ID。A function app on an App Service plan must have the serverFarmId property set to the resource ID of the plan created earlier.

{
    "apiVersion": "2016-03-01",
    "type": "Microsoft.Web/sites",
    "name": "[variables('functionAppName')]",
    "location": "[resourceGroup().location]",
    "kind": "functionapp",
    "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
    ],
    "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "siteConfig": {
            "appSettings": [
                {
                    "name": "AzureWebJobsStorage",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]"
                },
                {
                    "name": "FUNCTIONS_WORKER_RUNTIME",
                    "value": "node"
                },
                {
                    "name": "WEBSITE_NODE_DEFAULT_VERSION",
                    "value": "10.14.1"
                },
                {
                    "name": "FUNCTIONS_EXTENSION_VERSION",
                    "value": "~2"
                }
            ]
        }
    }
}

自定义部署Customizing a deployment

函数应用有许多可用于部署的子资源,包括应用设置和源代码管理选项。A function app has many child resources that you can use in your deployment, including app settings and source control options. 还可以选择删除 sourcecontrols 子资源,改用另一个部署选项。You also might choose to remove the sourcecontrols child resource, and use a different deployment option instead.

重要

若要使用 Azure 资源管理器成功部署应用程序,了解如何在 Azure 中部署资源尤为重要。To successfully deploy your application by using Azure Resource Manager, it's important to understand how resources are deployed in Azure. 在下面的示例中,通过使用 siteConfig 应用顶级配置。In the following example, top-level configurations are applied by using siteConfig. 请务必在顶级设置这些配置,因为这些配置会将信息传达给 Functions 运行时和部署引擎。It's important to set these configurations at a top level, because they convey information to the Functions runtime and deployment engine. 应用 sourcecontrols/web 子资源前,需要顶级信息。Top-level information is required before the child sourcecontrols/web resource is applied. 虽然可以在子级别 config/appSettings 资源中配置这些设置,但在某些情况下,需要在应用 config/appSettings 之前部署函数应用。Although it's possible to configure these settings in the child-level config/appSettings resource, in some cases your function app must be deployed before config/appSettings is applied. 比如在逻辑应用中使用函数时,函数是另一资源的依赖项。For example, when you are using functions with Logic Apps, your functions are a dependency of another resource.

{
  "apiVersion": "2015-08-01",
  "name": "[parameters('appName')]",
  "type": "Microsoft.Web/sites",
  "kind": "functionapp",
  "location": "[parameters('location')]",
  "dependsOn": [
    "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
    "[resourceId('Microsoft.Web/serverfarms', parameters('appName'))]"
  ],
  "properties": {
     "serverFarmId": "[variables('appServicePlanName')]",
     "siteConfig": {
        "alwaysOn": true,
        "appSettings": [
            {
                "name": "FUNCTIONS_EXTENSION_VERSION",
                "value": "~2"
            },
            {
                "name": "Project",
                "value": "src"
            }
        ]
     }
  },
  "resources": [
     {
        "apiVersion": "2015-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/Sites', parameters('appName'))]",
          "[resourceId('Microsoft.Web/Sites/sourcecontrols', parameters('appName'), 'web')]",
          "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
        ],
        "properties": {
          "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]",
          "AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=core.chinacloudapi.cn;AccountKey=', listKeys(variables('storageAccountid'),'2019-06-01').keys[0].value)]",
          "FUNCTIONS_EXTENSION_VERSION": "~2",
          "FUNCTIONS_WORKER_RUNTIME": "dotnet",
          "Project": "src"
        }
     },
     {
          "apiVersion": "2015-08-01",
          "name": "web",
          "type": "sourcecontrols",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites/', parameters('appName'))]"
          ],
          "properties": {
            "RepoUrl": "[parameters('sourceCodeRepositoryURL')]",
            "branch": "[parameters('sourceCodeBranch')]",
            "IsManualIntegration": "[parameters('sourceCodeManualIntegration')]"
          }
     }
  ]
}

提示

此模板使用 Project 应用设置值,这将设置基本目录,Functions 部署引擎 (Kudu) 在此目录中查找可部署代码。This template uses the Project app settings value, which sets the base directory in which the Functions deployment engine (Kudu) looks for deployable code. 在存储库内,函数位于 src 文件夹的子文件夹中。In our repository, our functions are in a subfolder of the src folder. 因此,在前一个示例中,将应用设置值设置为 srcSo, in the preceding example, we set the app settings value to src. 如果函数位于存储库的根目录中,或者不从源代码管理进行部署,则可删除此应用设置值。If your functions are in the root of your repository, or if you are not deploying from source control, you can remove this app settings value.

部署模板Deploy your template

可以使用以下任意方法部署模板:You can use any of the following ways to deploy your template:

“部署到 Azure”按钮Deploy to Azure button

<url-encoded-path-to-azuredeploy-json> 替换为 GitHub 中 azuredeploy.json 文件的原始路径的 URL 编码版本。Replace <url-encoded-path-to-azuredeploy-json> with a URL-encoded version of the raw path of your azuredeploy.json file in GitHub.

以下示例使用 Markdown:Here is an example that uses markdown:

[![Deploy to Azure](https://azuredeploy.net/deploybutton.png)](https://portal.azure.cn/#create/Microsoft.Template/uri/<url-encoded-path-to-azuredeploy-json>)

以下示例使用 HTML:Here is an example that uses HTML:

<a href="https://portal.azure.cn/#create/Microsoft.Template/uri/<url-encoded-path-to-azuredeploy-json>" target="_blank"><img src="https://azuredeploy.net/deploybutton.png"></a>

使用 PowerShell 进行部署Deploy using PowerShell

以下 PowerShell 命令创建一个资源组并部署一个模板,该模板创建函数应用及其必需的资源。The following PowerShell commands create a resource group and deploy a template that create a function app with its required resources. 若要在本地运行,必须安装 Azure PowerShellTo run locally, you must have Azure PowerShell installed. 运行 Connect-AzAccount -Environment AzureChinaCloud 进行登录。Run Connect-AzAccount -Environment AzureChinaCloud to sign in.

# Register Resource Providers if they're not already registered
Register-AzResourceProvider -ProviderNamespace "microsoft.web"
Register-AzResourceProvider -ProviderNamespace "microsoft.storage"

# Create a resource group for the function app
New-AzResourceGroup -Name "MyResourceGroup" -Location 'China North 2'

# Create the parameters for the file, which for this template is the function app name.
$TemplateParams = @{"appName" = "<function-app-name>"}

# Deploy the template
New-AzResourceGroupDeployment -ResourceGroupName "MyResourceGroup" -TemplateFile template.json -TemplateParameterObject $TemplateParams -Verbose

若要测试此部署,可以使用这样的模板,该模板在消耗计划中在 Windows 上创建函数应用。To test out this deployment, you can use a template like this one that creates a function app on Windows in a Consumption plan. <function-app-name> 替换为你的函数应用的唯一名称。Replace <function-app-name> with a unique name for your function app.

后续步骤Next steps

深入了解如何开发和配置 Azure Functions。Learn more about how to develop and configure Azure Functions.