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



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

ARM 文档页中的此表显示">是,已启用 APIM 资源管理器",但快速入门模板链接找不到 Microsoft.ApiManagement 资源类型的示例模板。然而,这可能仅仅意味着还没有人为画廊贡献模板,我必须编写自己的模板。

至于编写我自己的 ARM 模板,引导你编写资源管理器模板的文章说:

若要了解有关资源提供程序的大部分信息,请参阅资源管理器提供程序、区域、API 版本和架构

。它链接回与我上面的"此表"文本相同的页面。"创作模板"文章的同一部分还说:

[属性是] 特定于资源的配置设置。属性的值与您在用于创建资源的 REST API 操作(PUT 方法(的请求正文中提供的值完全相同。有关资源架构文档或 REST API 的链接,请参阅资源管理器提供程序、区域、API 版本和架构。

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

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

  • APIM REST API 要求您已经创建了一个 APIM 实例。它旨在操作 APIM 实例中的 APIM 资源,而不是首先用于创建 APIM 实例。
  • ARM 架构项目不包含 Microsoft.ApiManagement 的架构。字符串"api management"和"apim"不会出现在架构项目中。

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

是的,

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

PS C:WINDOWSsystem32> 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 中的快速入门 API 管理服务 ARM 模板。

New-AzureRmApiManagement可用于创建 APIM 实例。但预置 APIM 实例需要时间,通常为 20 到 30 分钟。如果必须创建多个实例,为了节省时间,最好使用 Azure 自动化 Runbook 执行此操作,并并行运行此命令。下面是一个示例。

最新更新