Azure ContainerInstanceManagement JavaScript 用戶端函式庫 - 版本 10.0.0

此套件包含 Azure ContainerInstanceManagement 用戶端的同型 SDK(在 Node.js 和瀏覽器中執行)。

容器實例

主要連結:

開始使用

目前支援的環境

如需詳細資訊,請參閱我們的支援原則。

Prerequisites

安裝 @azure/arm-containerinstance 套件

使用 npm安裝適用於 JavaScript 的 Azure ContainerInstanceManagement 用戶端連結庫:

npm install @azure/arm-containerinstance

建立和驗證 ContainerInstanceManagementClient

若要建立客戶端物件來存取 Azure ContainerInstanceManagement API,您需要 Azure ContainerInstanceManagement 資源的 endpoint 和 credential。 Azure ContainerInstanceManagement 用戶端可以使用 Azure Active Directory 認證進行驗證。 您可以在 Azure 入口網站中找到 Azure ContainerInstanceManagement 資源的端點。

你可以用@azure/identity庫的憑證或現有的AAD憑證來驗證Azure Active Directory。

若要使用如下所示的 DefaultAzureCredential 提供者,或 Azure SDK 所提供的其他認證提供者,請安裝 @azure/identity 套件:

npm install @azure/identity

您也必須 註冊新的 AAD 應用程式,並將適當的角色指派給服務主體,以授與 Azure ContainerInstanceManagement 的存取權(注意:"Owner" 等角色不會授與必要的許可權)。

想了解更多如何建立 Azure AD 應用程式的資訊,請參考 此指南。

使用類似 Node.js 和類似 Node 的環境,您可以使用類別 DefaultAzureCredential 來驗證用戶端。

import { ContainerInstanceManagementClient } from "@azure/arm-containerinstance";
import { DefaultAzureCredential } from "@azure/identity";

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

對於瀏覽器環境,請使用套件中的 InteractiveBrowserCredential 進行@azure/identity驗證。

import { InteractiveBrowserCredential } from "@azure/identity";
import { ContainerInstanceManagementClient } from "@azure/arm-containerinstance";

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

JavaScript 套件組合

若要在瀏覽器中使用此用戶端連結庫,您必須先使用配套程式。 如需如何執行這項操作的詳細資訊,請參閱我們的 組合檔。

關鍵概念

ContainerInstanceManagementClient

ContainerInstanceManagementClient是使用 Azure ContainerInstanceManagement 用戶端函式庫的開發者的主要介面。 探索此客戶端物件上的方法,以瞭解您可以存取的 Azure ContainerInstanceManagement 服務的不同功能。

Troubleshooting

Logging

啟用記錄可能有助於找出有關失敗的實用資訊。 若要查看 HTTP 要求和回應的記錄,請將 AZURE_LOG_LEVEL 環境變數設定為 info。 或者,您可以在運行時間啟用記錄,方法是在 setLogLevel中呼叫 @azure/logger:

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

setLogLevel("info");

如需如何啟用記錄的詳細指示,請參閱@azure/記錄器套件檔。

下一步

如需如何使用此連結庫的詳細範例,請參閱 範例 目錄。

Contributing

如果你想為這個函式庫貢獻,請閱讀 contributing guide,了解更多如何建置與測試程式碼。