我正在尝试通过 PowerShell 创建 Azure 函数。
首先,我使用基本计划成功做到了
$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
}
但是如果我将配置对象更改为:
$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 Doc1 中所示和 MS Doc2 , 消费计划不需要PlanName
,也不需要在消费模式下为功能应用创建应用服务计划。
这意味着,它将按照上述引用文献中的描述自动创建消费应用服务计划。
我已按照您的代码进行重现和解决,但没有给出计划名称,如下面的解决方法所示:
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 本身不允许在现有消费计划中创建另一个函数应用。
它只允许在现有托管计划类型(应用程序服务计划和高级类型)中创建其他功能应用程序,如下面的 Gif 图片所示:
关于azure - 通过 PowerShell 在消耗计划上创建 Azure 函数失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71388162/