如何以编程方式创建 API 管理服务?

How to create an API Management service programmatically?

我正在尝试以编程方式(如果可能,通过 Azure 资源管理器)在特定资源组中创建 APIM 服务。目标是我们可以拥有一个参数化的模板或脚本,并且可以签入源代码管理,以便我们可以复制和重新创建我们的环境。

This table in an ARM documentation page says Yes, Resource Manager is Enabled for APIM, but the Quickstart Templates link 找不到 Microsoft.ApiManagement 资源类型的示例模板。然而,这可能仅仅意味着还没有人向图库贡献模板,我必须自己编写。

关于编写自己的 ARM 模板,article that walks you through authoring a Resource Manager template 说:

To learn much of what you need to know about resource providers, see Resource Manager providers, regions, API versions and schemas

... 链接回与我上面的 "This table" 文本相同的页面。 "authoring templates"文章的同一节还说:

[Properties are] Resource specific configuration settings. The values for the properties are exactly the same as the values you provide in the request body for the REST API operation (PUT method) to create the resource. For links to resource schema documentation or REST API, see Resource Manager providers, regions, API versions and schemas.

...再次链接回与上面相同的页面。

我已经检查了 APIM REST API and the azure-resource-manager-schemas 页面以获取有关如何创建 APIM 实例的文档。

是否可以通过编程方式创建 API 管理服务,如果可以,如何创建?

是的,可以使用 Azure Powershell 1.0 命令行开关以编程方式创建 ApiManagement 服务 https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/。下面是可以帮助您实现它的命令行开关。

PS C:\WINDOWS\system32> get-help New-AzureRmApiManagement -example

NAME
New-AzureRmApiManagement

SYNOPSIS
Creates an API Management deployment.

SYNTAX
New-AzureRmApiManagement [-Capacity [<Int32>]] [-Sku [<PsApiManagementSku>]] [-Tags [<0, Culture=neutral,
PublicKeyToken=b77a5c561934e089>]] -AdminEmail <String> -Location {North Central US | South Central US | Central
US | West Europe | North Europe | West US | East US | East US 2 | Japan East | Japan West | Brazil South |
Southeast Asia | East Asia | Australia East | Australia Southeast} -Name <String> -Organization <String>
-ResourceGroupName <String> [<CommonParameters>]

Example 1: Create at Developer tier API Management service

PS C:\>New-AzureRmApiManagement -ResourceGroupName "ContosoGroup02" -Name "ContosoApi" -Location "Central US"
-Organization "Contoso" -AdminEmail "admin@contoso.com"


This command creates a Developer tier API Management service. The command specifies the organization and the
administrator address. The command does not specify the SKU parameter. Therefore, the cmdlet uses the default
value of Developer.


Example 2: Create a Standard tier service that has three units

PS C:\>New-AzureRmApiManagement -ResourceGroupName "ContosoGroup02 -Name "ContosoApi" -Location "Central US"
-Organization "Contoso" -AdminEmail "admin@contoso.com" -Sku Standard -Capacity 3


This command creates a Standard tier API Management service that has three units.

您可以使用

找到更多命令行开关
 get-Help AzureRmApiManagement

可以在此处找到命令行开关的完整文档 https://msdn.microsoft.com/en-us/library/mt619282.aspx

您现在可以使用 GitHub 中的 quickstart API Management Service ARM template

New-AzureRmApiManagement 可用于创建 APIM 实例。但是配置 APIM 实例需要时间,通常需要 20 到 30 分钟。如果您必须创建多个实例,为了节省时间,最好使用 Azure Automation 运行book 和 运行 并行执行此命令。 Here 就是一个例子。