繁体   English   中英

通过PowerShell创建消费计划Azure function失败

[英]Creating of Azure function on consumption plan via PowerShell fails

我正在尝试通过 PowerShell 创建一个 Azure Function。

首先我用基本计划成功做到了

$azFunctionAppServiceObject = @{
   location = $iothubLocation
   sku = @{
        name = "B1"
        tier = "Basic"
   }
   kind = "functionapp"
   properties = @{
        reserved = "false"
        kind = "functionapp"
   }
}

$appServicePlan = Get-AzResource -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.Web/serverfarms" -Name $appServicePlanName -ErrorAction SilentlyContinue

if (!$appServicePlan)
{
    $appServicePlan = New-AzResource -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.Web/serverfarms" -Name $appServicePlanName -IsFullObject -PropertyObject $azFunctionAppServiceObject -Force
}
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $blobStorageAccountName -ErrorAction SilentlyContinue
if (!$storageAccount)
{
    Write-Output ">----------- Creating storage account"
    $storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $blobStorageAccountName -SkuName Standard_LRS -Location $iothubLocation -Kind StorageV2 -AccessTier Hot
}

$trigger  = Get-AzFunctionApp -ResourceGroupName $resourceGroupName `
    -Name $FunctionAppName `

if (!$trigger)
{
    Write-Output ">----------- Creating trigger"

    New-AzFunctionApp -ResourceGroupName $resourceGroupName `
        -Name $FunctionAppName `
        -PlanName $appServicePlanName `
        -StorageAccount $blobStorageAccountName `
        -Runtime Dotnet `
        -FunctionsVersion 4 `
        -RuntimeVersion 6 `
        -OSType Windows
}

但是如果我将配置 object 更改为:

$azFunctionAppServiceObject = @{
   location = $iothubLocation
   sku = @{
        name = "Y1"
        tier = "Dynamic"
   }
   kind = "functionapp"
   properties = @{
        reserved = "false"
        kind = "functionapp"
   }
}

我得到

Az.Functions.internal\New-AzFunctionApp : The server responded with a Request Error, Status: Conflict At C:\Program Files\WindowsPowerShell\Modules\Az.Functions\4.0.1\custom\New-AzFunctionApp.ps1:528 char:17
+ ...             Az.Functions.internal\New-AzFunctionApp @PSBoundParameter ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ ResourceGroup...20190801.Site }:<>f__AnonymousType0`4) [New-AzFunctionApp_Create], RestException`1
    + FullyQualifiedErrorId : Conflict,Microsoft.Azure.PowerShell.Cmdlets.Functions.Cmdlets.NewAzFunctionApp_Create

如本MS Doc1MS Doc2中所述,消费计划不需要PlanName ,也不需要在消费模式下为 function 应用创建应用服务计划。

这意味着,它将按照上述参考资料中的描述自动创建消费应用程序服务计划。

我已经按照您的代码重现并解决了问题,但没有给出计划名称,您可以在下面的解决方法中看到:

在此处输入图像描述

PowerShell 代码:

$iothubLocation = 'Southeast Asia'
$resourceGroupName = 'hariRG'
$blobStorageAccountName = 'krishfuncblob'
$FunctionAppName = 'krishfuncapp12059'
$subscriptionId = 'xxxx-xxxx-xxxx-xxxx-xxx'


#=================Creating Azure Resource Group===============
$resourceGroup = Get-AzResourceGroup | Where-Object { $_.ResourceGroupName -eq $resourceGroupName }
if ($resourceGroup -eq $null)
{
  New-AzResourceGroup -Name $resourceGroupName -Location $location -force
}

#selecting default azure subscription by name
Select-AzSubscription -SubscriptionID $subscriptionId
Set-AzContext $subscriptionId


#========Creating Azure Storage Account========
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $blobStorageAccountName -ErrorAction SilentlyContinue


if (!$storageAccount)
{
    Write-Output ">----------- Creating storage account"
    $storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $blobStorageAccountName -SkuName Standard_LRS -Location $iothubLocation -Kind StorageV2 -AccessTier Hot
}



#========Creating Azure Function========
$trigger  = Get-AzFunctionApp -ResourceGroupName $resourceGroupName -Name $FunctionAppName

if (!$trigger)
{
    Write-Output ">----------- Creating trigger"

    New-AzFunctionApp -ResourceGroupName $resourceGroupName `
        -Name $FunctionAppName `
        -StorageAccount $blobStorageAccountName `
        -Runtime Dotnet `
        -FunctionsVersion 4 `
        -RuntimeVersion 6 `
        -OSType Windows
}

结果:

在此处输入图像描述

更新答案:

Azure Portal 本身不允许在现有消费计划中创建另一个 function 应用程序。

它只允许在现有的托管计划类型(应用程序服务计划和高级类型)中创建另一个 function 应用程序,如下面的 Gif 图像所示:

在此处输入图像描述

使用 PowerShell 在消费计划上创建 Azure Function 时,需要对New-AzFunctionApp调用使用不同的参数。 查看参数,您可以跳过-PlanName参数,而是使用-Location参数。

这里有一个关于如何执行操作的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM