Delen via


Een tabel maken met automatische schaalaanpassing voor Azure Cosmos DB - API voor Table

VAN TOEPASSING OP: Tafel

Notitie

Het wordt aanbevolen de Azure Az PowerShell-module te gebruiken om te communiceren met Azure. Zie Azure PowerShell installeren om aan de slag te gaan. Raadpleeg Azure PowerShell migreren van AzureRM naar Az om te leren hoe u naar de Azure PowerShell-module migreert.

Voor dit voorbeeld is Azure PowerShell Az 5.4.0 of hoger vereist. Voer Get-Module -ListAvailable Az uit om te zien welke versies zijn geïnstalleerd. Als u PowerShell moet installeren, raadpleegt u De Azure PowerShell-module installeren.

Voer Connect-AzAccount uit om u aan te melden bij Azure.

Voorbeeldscript

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Create Cosmos Table API account and a Table with autoscale 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 = "mjbArmTest"#"myResourceGroup" # Resource Group must already exist
$accountName = "cosmos-$uniqueId" # Must be all lower case
$consistencyLevel = "Session"
$tableName = "myTable"
$autoscaleMaxThroughput = 4000 #minimum = 4000
# --------------------------------------------------
Write-Host "Creating account $accountName"
$account = New-AzCosmosDBAccount -ResourceGroupName $resourceGroupName `
    -LocationObject $locations -Name $accountName -ApiKind $apiKind `
    -DefaultConsistencyLevel $consistencyLevel `
    -EnableAutomaticFailover:$true

Write-Host "Creating Table $tableName"
$table = New-AzCosmosDBTable -ParentObject $account `
    -Name $tableName -AutoscaleMaxThroughput $autoscaleMaxThroughput

Opschonen van implementatie

Na het uitvoeren van het voorbeeldscript kan de volgende opdracht worden gebruikt om de resourcegroep en alle resources die er aan zijn gekoppeld te verwijderen.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Uitleg van het script

In dit script worden de volgende opdrachten gebruikt. Elke opdracht in de tabel is een koppeling naar specifieke documentatie over de opdracht.

Opdracht Opmerkingen
Azure Cosmos DB
New-AzCosmosDBAccount Hiermee maakt u een Azure Cosmos DB-account.
New-AzCosmosDBTable Hiermee maakt u een API voor Table Table.
Azure-resourcegroepen
Remove-AzResourceGroup Hiermee verwijdert u een resourcegroep met inbegrip van alle ingesloten resources.

Volgende stappen

Zie Documentatie over Azure PowerShell voor meer informatie over Azure PowerShell.