微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Az CLI/PowerShell 从 Function App 重新导入 API 管理 API

如何解决使用 Az CLI/PowerShell 从 Function App 重新导入 API 管理 API


我使用“从 Azure 函数导入”将 Azure 函数实例添加到 API 管理 API。
当我更新 Azure Functions 实例时,它不会自动更新 API 管理 API。 我到处搜索能够将我的 Azure 函数重新导入到我的 API 管理 API 中的命令,但我找不到任何解决方案/解决方法

这就是我想要自动化的:

enter image description here

enter image description here

解决方法

很遗憾,我们暂时无法使用 CliPowershellAzure function 重新导入 API Management

你可以参考这个问题:

https://docs.microsoft.com/en-us/answers/questions/226573/link-existing-function-app-with-apim-using-azure-c.html

,

没有内置的 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

enter image description here

签入门户:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。