다음을 통해 공유


Azure CLI를 사용하여 Azure Cosmos DB for 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 서버리스 계정 및 API for Table 테이블을 만듭니다. 리소스를 만드는 데 시간이 걸릴 수 있습니다.

# Create a Table API serverless account and table

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="serverless-table-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
table="msdocs-table-cosmos-$randomIdentifier"

# 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 EnableServerless --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False \

# Create a Table API Table
az cosmosdb table create --account-name $account --resource-group $resourceGroup --name $table

이 스크립트는 다음 명령을 사용합니다.

  • az group create는 모든 리소스를 저장할 리소스 그룹을 만듭니다.
  • --capabilities EnableTable EnableServerless가 있는 az cosmosdb create는 API for Table에 대한 Azure Cosmos DB 서버리스 계정을 만듭니다.
  • az cosmosdb table create는 Azure Cosmos DB for Table 테이블을 만듭니다.

리소스 정리

만든 리소스가 더 이상 필요하지 않은 경우 az group delete 명령을 사용하여 리소스 그룹과 여기에 포함된 모든 리소스를 삭제합니다. 이러한 리소스에는 Azure Cosmos DB 계정 및 테이블이 포함됩니다. 리소스를 삭제하는 데 시간이 걸릴 수 있습니다.

az group delete --name $resourceGroup

다음 단계

Azure Cosmos DB CLI 설명서