【问题标题】:How to Create a Powershell Script to Create Azure API Management Resource如何创建 Powershell 脚本来创建 Azure API 管理资源
【发布时间】:2019-08-13 16:06:05
【问题描述】:

我试图弄清楚如何从脚本创建 API 管理资源和 API 管理 API。我相信有两种选择:

.

  1. 使用 AzureRm.ApiManagement 中的 powershell Management api

    为此,我相信要使用的两个命令是:

    新 AzureRmApiManagement

    New-AzureRmApiManagementApi

  1. 使用管理 REST API

    为此,我相信创建资源需要使用第一个选项,然后可以通过 Invoke-RestMethod powershell 命令使用以下方法:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}?api-version=2019-01- 01

.

我只想传递新的管理 api 资源的名称和 devlab 的名称以在其下创建它并创建它,然后在其下创建一个不与产品关联(或与无限关联)的 api默认产品...以更容易的为准)。

任何人都可以帮助使用 powershell 脚本来执行此操作吗?

谢谢。

【问题讨论】:

    标签: azure powershell azure-api-management api-management apim


    【解决方案1】:

    当您运行命令“New-AzureRmApiManagementApi”时,您只是创建了一个 api,该 api 不会添加到产品中。您需要运行命令“Add-AzureRmApiManagementApiToProduct”将 api 添加到产品中。我的脚本如下

    $ResourceGroupName=""
    $sku=""
    $name="" 
    $Location=""                   
    $Organization=""
    $AdminEmail=""
    $apiName=" #the name of the web API."
    $url="" #the URL of the web service that exposes the API.
    $path="" #the web API path, which is the last part of the API's public URL and corresponds to the Web API URL suffix field in the admin portal.
    
    #login azure
    Connect-AzureRmAccount
    
    #create api management instance with required parameters
    New-AzureRmApiManagement -ResourceGroupName $ResourceGroupName -Name $name -Sku $sku -Location $Location -Organization $Organization -AdminEmail $AdminEmail
    
    $ApiMgmtContext =New-AzureRmApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $name
    
    #create api
    $api = New-AzureRmApiManagementApi -Context $ApiMgmtContext -Name $apiName -ServiceUrl $url -Protocols @("http", "https") -Path $path
    
    #run the command if you do not know product id
    Get-AzureRmApiManagementProduct -Context $ApiMgmtContext
    
    #add api to product
    Add-AzApiManagementApiToProduct -Context $ApiMgmtContext -ProductId "" -ApiId $api.ApiId
    

    有关Azure API管理powershell命令的更多详细信息,请参考document

    【讨论】:

    • @JackSojourn 你可以吗?有更新吗?
    • 谢谢吉姆!正是我需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    相关资源
    最近更新 更多