Share via


使用 Azure CLI 來建立 API for Gremlin 帳戶、資料庫及具有自動調整功能的圖表

適用於: Gremlin

此文章中的指令碼會建立 Azure Cosmos DB for Gremlin 帳戶、資料庫,以及具有自動調整功能的圖表。

必要條件

  • 如果您沒有 Azure 訂用帳戶,請在開始之前先建立 Azure 免費帳戶

  • 此指令碼需要 Azure CLI 2.30 版或更新版本。

    • 您可以在 Azure Cloud Shell 的 Bash 環境中執行指令碼。 Cloud Shell 開啟時,請務必在殼層視窗左上方的環境欄位中選取 Bash。 Cloud Shell 具有最新版的 Azure CLI。

    • 您可以視需要安裝 Azure CLI 以在本機執行指令碼。 執行 az version 以找出您的 Azure CLI 版本,如果需要升級,請執行 az upgrade。 執行 az login 以登入 Azure。

範例指令碼

此指令碼會使用下列命令:

# Create a Gremlin API database and graph with autoscale

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="autoscale-gremlin-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-gremlin-cosmos"
graph="msdocs-graph1-gremlin-cosmos"
partitionKey="/partitionKey"
maxThroughput=1000 #minimum = 1000

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for Gremlin API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableGremlin --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False

# Create a Gremlin database
echo "Creating $database with $account"
az cosmosdb gremlin database create --account-name $account --resource-group $resourceGroup --name $database

# Create a Gremlin graph with autoscale
echo "Creating $graph"
az cosmosdb gremlin graph create --account-name $account --resource-group $resourceGroup --database-name $database --name $graph --partition-key-path $partitionKey --max-throughput $maxThroughput

刪除資源

如果您不需要指令碼建立的資源,請使用 az group delete 命令來刪除資源群組及其包含的所有資源,包括 Azure Cosmos DB 帳戶和資料庫。

az group delete --name $resourceGroup

下一步

Azure Cosmos DB CLI 文件