快速入门:使用 PowerShell 创建新的 Azure API 管理服务实例Quickstart: Create a new Azure API Management service instance by using PowerShell

Azure API 管理 (APIM) 可帮助组织将 API 发布给外部、合作伙伴和内部开发人员,以充分发挥其数据和服务的潜力。Azure API Management (APIM) helps organizations publish APIs to external, partner, and internal developers to unlock the potential of their data and services. API 管理通过开发人员参与、商业洞察力、分析、安全性和保护提供了核心竞争力以确保成功的 API 程序。API Management provides the core competencies to ensure a successful API program through developer engagement, business insights, analytics, security, and protection. 使用 APIM 可以为在任何位置托管的现有后端服务创建和管理新式 API 网关。APIM enables you to create and manage modern API gateways for existing backend services hosted anywhere. 有关详细信息,请参阅概述For more information, see the Overview.

本快速入门介绍使用 Azure PowerShell cmdlet 新建 API 管理实例的步骤。This quickstart describes the steps for creating a new API Management instance by using Azure PowerShell cmdlets.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

如果选择在本地安装并使用 PowerShell,则本教程需要安装 Azure PowerShell 模块 1.0 或更高版本。If you choose to install and use the PowerShell locally, this tutorial requires the Azure PowerShell module version 1.0 or later. 运行 Get-Module -ListAvailable Az 即可查找版本。Run Get-Module -ListAvailable Az to find the version. 如果需要升级,请参阅安装 Azure PowerShell 模块If you need to upgrade, see Install Azure PowerShell module. 如果在本地运行 PowerShell,则还需运行 Connect-AzAccount 以创建与 Azure 的连接。If you're running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.

创建资源组Create resource group

使用 New-AzResourceGroup 创建 Azure 资源组。Create an Azure resource group with New-AzResourceGroup. 资源组是在其中部署和管理 Azure 资源的逻辑容器。A resource group is a logical container into which Azure resources are deployed and managed.

以下命令在“中国北部”位置创建名为“myResourceGroup”的资源组:The following command creates a resource group named myResourceGroup in the China North location:

New-AzResourceGroup -Name myResourceGroup -Location ChinaNorth

创建 API 管理服务Create an API Management service

现在,你已有了一个资源组,可以创建 API 管理服务实例了。Now that you have a resource group, you can create an API Management service instance. 使用 New-AzApiManagement 创建一个 API 管理服务实例,并提供服务名称和发布者详细信息。Create one by using New-AzApiManagement and provide a service name and publisher details. 服务名称在 Azure 中必须独一无二。The service name must be unique within Azure.

在下面的示例中,使用“myapim”作为服务名称。In the following example, myapim is used for the service name. 将该名称更新为唯一值。Update the name to a unique value. 同时更新 API 发布者的组织名称和管理员电子邮件地址以接收通知。Also update the organization name of the API publisher and the admin email address to receive notifications.

默认情况下,该命令在“开发人员”层创建实例,这是评估 Azure API 管理的一个经济选择。By default, the command creates the instance in the Developer tier, an economical option to evaluate Azure API Management. 此层不用于生产。This tier isn't for production use. 有关对 API 管理层进行缩放的详细信息,请参阅升级和缩放For more information about scaling the API Management tiers, see upgrade and scale.

备注

此操作将运行较长时间。This is a long-running operation. 在此层中创建和激活 API 管理服务可能需要 30 到 40 分钟。It can take between 30 and 40 minutes to create and activate an API Management service in this tier.

New-AzApiManagement -Name "myapim" -ResourceGroupName "myResourceGroup" `
  -Location "China North" -Organization "Contoso" -AdminEmail "admin@contoso.com" 

当该命令返回时,运行 Get-AzApiManagement 可查看 Azure API 管理服务的属性。When the command returns, run Get-AzApiManagement to view the properties of the Azure API Management service. 激活后,预配状态为“Succeeded”,并且服务实例具有多个关联的 URL。After activation, the provisioning status is Succeeded and the service instance has several associated URLs. 例如: 。For example:

Get-AzApiManagement -Name "myapim" -ResourceGroupName "myResourceGroup" 

示例输出:Example output:

PublicIPAddresses                     : {203.0.113.1}
PrivateIPAddresses                    :
Id                                    : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.ApiManagement/service/myapim
Name                                  : myapim
Location                              : China North
Sku                                   : Developer
Capacity                              : 1
CreatedTimeUtc                        : 9/9/2020 9:07:43 PM
ProvisioningState                     : Succeeded
RuntimeUrl                            : https://myapim.azure-api.net
RuntimeRegionalUrl                    : https://myapi-chinanorth-01.regional.azure-api.net
PortalUrl                             : https://myapim.portal.azure-api.net
DeveloperPortalUrl                    : https://myapim.developer.azure-api.net
ManagementApiUrl                      : https://myapim.management.azure-api.net
ScmUrl                                : https://myapim.scm.azure-api.net
PublisherEmail                        : admin@contoso.com
OrganizationName                      : Contoso
NotificationSenderEmail               : apimgmt-noreply@mail.windowsazure.cn
VirtualNetwork                        :
VpnType                               : None
PortalCustomHostnameConfiguration     :
ProxyCustomHostnameConfiguration      : {myapim.azure-api.net}
ManagementCustomHostnameConfiguration :
ScmCustomHostnameConfiguration        :
DeveloperPortalHostnameConfiguration  :
SystemCertificates                    :
Tags                                  : {}
AdditionalRegions                     : {}
SslSetting                            : Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagementSslSetting
Identity                              :
EnableClientCertificate               :
ResourceGroupName                     : myResourceGroup

部署 API 管理服务实例后,便可以使用它了。After your API Management service instance is deployed, you're ready to use it. 导入并发布第一个 API 教程开始。Start with the tutorial to import and publish your first API.

清理资源Clean up resources

如果不再需要资源组和所有相关资源,可以使用 Remove-AzResourceGroup 命令将其删除。When no longer needed, you can use the Remove-AzResourceGroup command to remove the resource group and all related resources.

Remove-AzResourceGroup -Name myResourceGroup

后续步骤Next steps