Share via


Azure CLI を使用して、Azure Cosmos DB for Table アカウントと自動スケーリングを使用するテーブルを作成する

適用対象: Table

この記事のスクリプトでは、Azure Cosmos DB for Table アカウントと自動スケーリングするテーブルが作成されます。

前提条件

  • Azure サブスクリプションをお持ちでない場合は、開始する前に Azure 無料アカウントを作成してください。

  • このスクリプトでは、Azure CLI バージョン 2.12.1 以降が必要となります。

    • このスクリプトは、Azure Cloud Shell の Bash 環境で実行できます。 Cloud Shell が開いたら、シェル ウィンドウの左上にある環境フィールドで Bash が表示されていることを確認択してください。 Cloud Shell には常に Azure CLI の最新バージョンがあります。

      Cloud Shell は、Azure portal へのサインインに使用したアカウントで自動的に認証されます。 az account set を使用して、別のサブスクリプションでサインインすることができ、<subscriptionId> をご使用の Azure サブスクリプション ID に置き換えます。

      subscription="<subscriptionId>" # add subscription here
      
      az account set -s $subscription # ...or use 'az login'
      
    • 必要に応じて、Azure CLI をインストールしてスクリプトをローカルで実行できます。 az version を実行して、Azure CLI のバージョンと、インストールされている依存ライブラリを確認し、アップグレードする必要がある場合は az upgrade を実行します。 メッセージが表示されたら、Azure CLI 拡張機能をインストールします。 Windows または macOS を実行している場合は、Docker コンテナーで Azure CLI を実行することを検討してください。

      ローカル インストールを使用する場合は、az login を実行して Azure にサインインし、プロンプトに従います。 その他のサインイン オプションについては、Azure CLI でのサインインに関するページを参照してください。

サンプル スクリプト

次のスクリプトを実行して、Azure リソース グループ、Azure Cosmos DB for Table アカウント、および自動スケール機能を備えた Table 用 API テーブルを作成します。 リソースの作成には、時間がかかる場合があります。

# Create a Table API table with autoscale

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="autoscale-table-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
table="msdocs-table-cosmos-$randomIdentifier"
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 Table API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableTable --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False

# Create a Table API Table with autoscale
echo "Create $table with $maxThroughput"
az cosmosdb table create --account-name $account --resource-group $resourceGroup --name $table --max-throughput $maxThroughput

このスクリプトでは以下のコマンドを使用します。

  • az group create: すべてのリソースを格納するリソース グループが作成されます。
  • az cosmosdb create--capabilities EnableTable を追加: Table 用 API のための Azure Cosmos DB アカウントを作成します。
  • az cosmosdb table create--max-throughput 1000 を追加: 自動スケール機能を備えた Azure Cosmos DB for Table テーブルを作成します。

リソースをクリーンアップする

作成したリソースが必要ない場合は、az group delete コマンドを使用して、リソース グループとそれに含まれるすべてのリソースを削除します。 これらのリソースには、Azure Cosmos DB アカウントとテーブルが含まれます。 リソースの削除には、時間がかかる場合があります。

az group delete --name $resourceGroup

次の手順