快速入门:使用 Azure CLI 创建新的 Azure API 管理服务实例(预览版)Quickstart: Create a new Azure API Management service instance by using the Azure CLI (preview)

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 CLI 中使用 az apim 命令创建新的 API 管理实例的步骤。This quickstart describes the steps for creating a new API Management instance using az apim commands in the Azure CLI. az apim 命令组中的命令当前为预览版,在将来的版本中可能会更改或删除。The commands in the az apim command group are currently in preview and may be changed or removed in a future release.

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

启动 Azure CLILaunch Azure CLI

可以使用 Azure CLI 来完成此快速入门。You can use the Azure CLI to complete this quickstart. 如果想要在本地使用它,建议使用 2.11.1 或更高版本。If you'd like to use it locally, version 2.11.1 or later is recommended. 运行 az --version 即可查找版本。Run az --version to find the version. 如果需要进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

备注

在 Azure China 中使用 Azure CLI 2.0 之前,请首先运行 az cloud set -n AzureChinaCloud 更改云环境。Before you can use Azure CLI 2.0 in Azure China, please run az cloud set -n AzureChinaCloud first to change the cloud environment. 如果要切换回全局 Azure,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Global Azure, run az cloud set -n AzureCloud again.

创建资源组Create a resource group

Azure API 管理实例像所有 Azure 资源一样必须部署到资源组中。Azure API Management instances, like all Azure resources, must be deployed into a resource group. 使用资源组可以组织和管理相关的 Azure 资源。Resource groups allow you to organize and manage related Azure resources.

首先,使用以下 az group create 命令在“中国东部”位置中创建名为“myResourceGroup”的资源组:First, create a resource group named myResourceGroup in the China East location with the following az group create command:

az group create --name myResourceGroup --location chinaeast

创建新服务Create a new service

现在,你已有了一个资源组,可以创建 API 管理服务实例了。Now that you have a resource group, you can create an API Management service instance. 使用 az apim create 命令创建一个,并提供服务名称和发布者详细信息。Create one by using the az apim create command 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 name of the API publisher's organization and the email address to receive notifications.

az apim create --name myapim --resource-group myResourceGroup \
  --publisher-name Contoso --publisher-email admin@contoso.com \
  --no-wait

默认情况下,该命令在“开发人员”层创建实例,这是评估 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.

提示

在此层中创建和激活 API 管理服务可能需要 30 到 40 分钟。It can take between 30 and 40 minutes to create and activate an API Management service in this tier. 上一命令使用了 --no-wait 选项,因此在创建服务后该命令会立即返回。The previous command uses the --no-wait option so that the command returns immediately while the service is created.

通过运行 az apim show 命令检查部署的状态:Check the status of the deployment by running the az apim show command:

az apim show --name myapim --resource-group myResourceGroup --output table

最初,输出类似于以下内容,显示了 Activating 状态:Initially, output is similar to the following, showing the Activating status:

NAME         RESOURCE GROUP    LOCATION    GATEWAY ADDR    PUBLIC IP    PRIVATE IP    STATUS      TIER       UNITS
-----------  ----------------  ----------  --------------  -----------  ------------  ----------  ---------  -------
myapim       myResourceGroup   China East                                             Activating  Developer  1

激活后,状态为 Online,服务实例有网关地址和公共 IP 地址。After activation, the status is Online and the service instance has a gateway address and public IP address. 目前,这些地址不会公开任何内容。For now, these addresses don't expose any content. 例如: 。For example:

NAME         RESOURCE GROUP    LOCATION    GATEWAY ADDR                       PUBLIC IP     PRIVATE IP    STATUS    TIER       UNITS
-----------  ----------------  ----------  ---------------------------------  ------------  ------------  --------  ---------  -------
myapim       myResourceGroup   China East  https://myapim.azure-api.net       203.0.113.1                 Online    Developer  1

当 API 管理服务实例处于联机状态时,便可以使用它了。When your API Management service instance is online, you're ready to use it. 导入并发布第一个 API 教程开始。Start with the tutorial to import and publish your first API.

清理资源Clean up resources

如果不再需要资源组和 API 管理服务实例,可以使用 az group delete 命令将其删除。When no longer needed, you can use the az group delete command to remove the resource group and the API Management service instance.

az group delete --name myResourceGroup

后续步骤Next steps