问题描述
我使用“从 Azure 函数导入”将 Azure 函数实例添加到 API 管理 API。
当我更新 Azure Functions 实例时,它不会自动更新 API 管理 API。 我到处搜索能够将我的 Azure 函数重新导入到我的 API 管理 API 中的命令,但我找不到任何解决方案/解决方法。
这就是我想要自动化的:
解决方法
很遗憾,我们暂时无法使用 Cli
或 Powershell
将 Azure function
重新导入 API Management
。
你可以参考这个问题:
,没有内置的 Azure Powershell/CLI 命令来执行此操作,在这种情况下,您可以简单地调用 REST API - Apis - Create Or Update
直接使用 powershell Invoke-AzRestMethod
或 CLI az rest
.
Powershell 示例:
$groupname = "xxxxxxx"
$APIMname = "joyapim"
$FullApiVersionName = "joyfunapim-v2"
$sourceApiName = "joyfunapim"
$apiVersion = "v2"
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $groupname -ServiceName $APIMname
$Api = Get-AzApiManagementApi -Context $ApiMgmtContext -ApiId $sourceApiName
$apiVersionSetId = (Get-AzApiManagementApiVersionSet -Context $ApiMgmtContext | Where-Object {$_.DisplayName -eq $sourceApiName}).ApiVersionSetId
$Apim = Get-AzApiManagement -ResourceGroupName $groupname -Name $APIMname
$path = $Apim.Id + "/apis/" + $ApiFullVersionName + ";rev=1?api-version=2019-12-01"
$payload = @{
"properties" = @{
"sourceApiId" = $Api.Id
"apiVersion" = $apiVersion
"apiVersionSetId" = "/apiVersionSets/"+ $apiVersionSetId
"apiVersionSet" = @{
"versioningScheme" = "Segment"
"name" = $sourceApiName
}
}
} | ConvertTo-Json -Depth 10
Invoke-AzRestMethod -Path $path -Method PUT -Payload $payload
签入门户: