使用PowerShell在Free App Service Plan中创建功能

问题描述

如何在具有“免费” SKU的App Service计划中创建Azure功能

New-AzFunctionApp似乎认为alwaysOn函数,免费SKU不支持。曾经是-Properties @{alwaysOn=$False}做到了这一点,但现在不再可用。尝试了-AppSettings,但无济于事。

解决方法

不幸的是,关于在Powershell中使用AlwaysOn = false创建功能应用程序的功能,有一个开放的issue。较简单的选择是使用ARM模板,该模板可以按所需方式正常工作。 https://github.com/Azure/azure-quickstart-templates/tree/master/101-function-app-create-dedicated

但是,如果您想坚持使用ps cmdlet,可以采取以下措施。

  1. 分别使用“基本” SKU创建“应用服务计划”
  2. 通过将上面创建的计划作为参数传递给New-AzFunctionApp来创建功能应用。现在将具有AlwaysOn = true。
  3. 将功能应用更新为AlwaysOn = false。
  4. 将应用程序服务计划更新为“免费”层。

下面是执行上述步骤的示例PS命令,请相应地更新参数。

New-AzAppServicePlan -ResourceGroupName "myRGName" -Name "myFuncAppName" -Location "West US"  -Tier "Basic"

New-AzFunctionApp -ResourceGroupName "myRGName" -Name "myFuncAppName" -PlanName "myFuncAppName" -StorageAccountName "myStorageName" -Runtime Dotnet # update Runtime as per your need

$funcApp = Get-AzResource -ResourceType 'microsoft.web/sites' -ResourceGroupName 'myRGName' -ResourceName 'myFuncAppName'
$funcApp | Set-AzResource -PropertyObject @{"siteConfig" = @{"AlwaysOn" = $false}} -Force

Set-AzAppServicePlan -Name 'myFuncAppName' -ResourceGroupName 'myRGName' -Tier Free -WorkerSize Small