使用 Azure CLI 创建 Gremlin 无服务器帐户、数据库和图

适用对象: Gremlin

本文中的脚本创建 Azure Cosmos DB for Gremlin 无服务器帐户、数据库和图。

先决条件

  • 如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅

  • 此脚本需要使用 Azure CLI 2.30 或更高版本。

    注意

    在可以在由世纪互联运营的 Microsoft Azure 中使用 Azure CLI 之前,请先运行 az cloud set -n AzureChinaCloud 来更改云环境。 若要切换回 Azure 公有云,请再次运行 az cloud set -n AzureCloud

示例脚本

此脚本使用以下命令:

# Create a Gremlin serverless account, database and graph

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="chinaeast2"
failoverLocation="chinanorth2"
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 文档