你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 JavaScript 的 Azure 部署客户端库 - 版本 1.0.0-beta.1

此包包含用于 Azure 部署客户端的同构 SDK(在 Node.js 和浏览器中运行)。

Deployments Client

Source code | Package (NPM) | API reference documentation | Samples

Getting started

当前支持的环境

See our support policy for more details.

Prerequisites

安装 @azure/arm-resourcesdeployments

使用以下命令 npm安装适用于 JavaScript 的 Azure 部署客户端库:

npm install @azure/arm-resourcesdeployments

创建和验证 DeploymentsClient

若要创建客户端对象以访问 Azure 部署 API,需要 Azure 部署资源credential的 和 endpoint . Azure 部署客户端可以使用 Azure Active Directory 凭据进行身份验证。 You can find the endpoint for your Azure Deployments resource in the Azure Portal.

You can authenticate with Azure Active Directory using a credential from the @azure/identity library or an existing AAD Token.

To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, please install the @azure/identity package:

npm install @azure/identity

你还需要 注册一个新的 AAD 应用程序,并通过 向服务主体分配合适的角色来授予对 Azure 部署的访问权限(注意:诸如此类 "Owner" 的角色不会授予必要的权限)。

For more information about how to create an Azure AD Application check out this guide.

使用 Node.js 和类似 Node 的环境,可以使用 DefaultAzureCredential 类对客户端进行身份验证。

import { DeploymentsClient } from "@azure/arm-resourcesdeployments";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new DeploymentsClient(new DefaultAzureCredential(), subscriptionId);

对于浏览器环境,请使用 InteractiveBrowserCredential 包中的 @azure/identity 进行身份验证。

import { InteractiveBrowserCredential } from "@azure/identity";
import { DeploymentsClient } from "@azure/arm-resourcesdeployments";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
  tenantId: "<YOUR_TENANT_ID>",
  clientId: "<YOUR_CLIENT_ID>",
});
const client = new DeploymentsClient(credential, subscriptionId);

JavaScript Bundle

若要在浏览器中使用此客户端库,首先需要使用捆绑程序。 For details on how to do this, please refer to our bundling documentation.

Key concepts

DeploymentsClient

DeploymentsClient 是使用 Azure 部署客户端库的开发人员的主要接口。 浏览此客户端对象上的方法,了解可以访问的 Azure 部署服务的不同功能。

Troubleshooting

Logging

启用日志记录可能有助于发现有关故障的有用信息。 若要查看 HTTP 请求和响应的日志,请将 AZURE_LOG_LEVEL 环境变量设置为 info。 或者,可以在运行时通过调用 setLogLevel 中的 @azure/logger 来启用日志记录:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

有关如何启用日志的更详细说明,请查看 @azure/logger 包文档

Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.