Share via


使用 Azure CLI 建立 Gremlin 無伺服器帳戶、資料庫和圖形

適用於: Gremlin

本文中的腳本會建立適用於 Gremlin 無伺服器帳戶、資料庫和圖表的 Azure Cosmos DB。

必要條件

  • 如果您沒有 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 serverless account, database and graph

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

# 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 EnableServerless --default-consistency-level Eventual --locations regionName="$failoverLocation" 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
echo "Creating $graph"
az cosmosdb gremlin graph create --account-name $account --resource-group $resourceGroup --database-name $database --name $graph --partition-key-path $partitionKey

刪除資源

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

az group delete --name $resourceGroup

下一步

Azure Cosmos DB CLI 文件