使用 PowerShell 在免费应用服务计划中创建函数

Create Function in Free App Service Plan using PowerShell

如何在具有 'Free' SKU 的应用服务计划中创建 Azure 函数。

New-AzFunctionApp 似乎默认为 alwaysOn 功能,免费 SKU 不支持该功能。曾经是 -Properties @{alwaysOn=$False} 成功了,但现在已经不可用了。尝试了 -AppSettings 但无济于事。

不幸的是,有一个开放的issue regarding the ability to create function app with AlwaysOn=false in Powershell. The easier option is to use an ARM template which works fine as the way you want. 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 命令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