Membuat tabel untuk Azure Cosmos DB - API Tabel
BERLAKU UNTUK:
API Tabel
Catatan
Artikel ini menggunakan modul Azure Az PowerShell, yang merupakan modul PowerShell yang direkomendasikan untuk berinteraksi dengan Azure. Untuk mulai menggunakan modul Az PowerShell, lihat Menginstal Azure PowerShell. Untuk mempelajari cara bermigrasi ke modul Az PowerShell, lihat Memigrasikan Azure PowerShell dari AzureRM ke Az.
Sampel ini memerlukan Azure PowerShell Az 5.4.0 atau yang lebih baru. Jalankan Get-Module -ListAvailable Az untuk melihat versi mana yang dipasang.
Jika Anda perlu memasang, lihat Pasang modul Azure PowerShell.
Jalankan Connect-AzAccount untuk masuk ke Azure.
Skrip sampel
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Create Cosmos Table API account and a Table with dedicated throughput
# --------------------------------------------------
Function New-RandomString{Param ([Int]$Length = 10) return $(-join ((97..122) + (48..57) | Get-Random -Count $Length | ForEach-Object {[char]$_}))}
# --------------------------------------------------
$uniqueId = New-RandomString -Length 7 # Random alphanumeric string for unique resource names
$apiKind = "Table"
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$locations = @()
$locations += New-AzCosmosDBLocationObject -LocationName "East Us" -FailoverPriority 0 -IsZoneRedundant 0
$locations += New-AzCosmosDBLocationObject -LocationName "West Us" -FailoverPriority 1 -IsZoneRedundant 0
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "cosmos-$uniqueId" # Must be all lower case
$consistencyLevel = "Session"
$tags = @{Tag1 = "MyTag1"; Tag2 = "MyTag2"; Tag3 = "MyTag3"}
$tableName = "myTable"
$tableRUs = 400
# --------------------------------------------------
Write-Host "Creating account $accountName"
$account = New-AzCosmosDBAccount -ResourceGroupName $resourceGroupName `
-LocationObject $locations -Name $accountName -ApiKind $apiKind -Tag $tags `
-DefaultConsistencyLevel $consistencyLevel `
-EnableAutomaticFailover:$true
Write-Host "Creating Table $tableName"
New-AzCosmosDBTable -ParentObject $account `
-Name $tableName -Throughput $tableRUs
Membersihkan penyebaran
Setelah sampel skrip dijalankan, perintah berikut dapat digunakan untuk menghapus grup sumber daya dan semua sumber daya yang terkait.
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
Penjelasan skrip
Skrip ini menggunakan perintah berikut. Setiap perintah dalam tabel menautkan ke dokumentasi perintah tertentu.
| Perintah | Catatan |
|---|---|
| Azure Cosmos DB | |
| New-AzCosmosDBAccount | Membuat Akun Cosmos DB. |
| New-AzCosmosDBTable | Membuat Tabel Table API. |
| Grup Sumber Daya Azure | |
| Remove-AzResourceGroup | Menghapus grup sumber daya termasuk semua sumber daya berlapis. |
Langkah berikutnya
Untuk informasi selengkapnya tentang Azure PowerShell, lihat dokumentasi Azure PowerShell.