简体   繁体   English

在Powershell中使用Azure CLI创建CosmosDB

[英]Creating CosmosDB with Azure CLI in powershell

I'm trying to create a new cosmosdb but getting the below error when I execute below code. 我正在尝试创建新的cosmosdb,但是在执行以下代码时却收到以下错误。

az cosmosdb create --name TIC_Test
                    --resource-group "TIC" 
                    --default-consistency-level  Session  
                    --locations "Central US"=0 "Central US"=0 
                    --max-interval 5  --max-staleness-prefix 100  
                    --enable-automatic-failover false  
                    --enable-virtual-network false  
                    --kind GlobalDocumentDB

Error: 错误:

az : usage: az cosmosdb create [-h] [--verbose] [--debug]
At line:2 char:1
+ az cosmosdb create --name TIC_Test --resource-group "TIC"  --default- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (usage: az cosmo...bose] [--debug]:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

                          [--output {json,jsonc,table,tsv}] [--query JMESPATH]
                          --resource-group RESOURCE_GROUP_NAME --name
                          ACCOUNT_NAME [--locations LOCATIONS [LOCATIONS ...]]
                          [--tags [TAGS [TAGS ...]]]
                          [--kind {GlobalDocumentDB,MongoDB,Parse}]
                          [--default-consistency-level {Eventual,Session,BoundedStaleness,Strong,ConsistentPrefix}]
                          [--max-staleness-prefix MAX_STALENESS_PREFIX]
                          [--max-interval MAX_INTERVAL]
                          [--ip-range-filter IP_RANGE_FILTER [IP_RANGE_FILTER ...]]
                          [--enable-automatic-failover [{true,false}]]
                          [--capabilities CAPABILITIES [CAPABILITIES ...]]
                          [--enable-virtual-network [{true,false}]]
                          [--virtual-network-rules VIRTUAL_NETWORK_RULES [VIRTUAL_NETWORK_RULES ...]]
                          [--subscription _SUBSCRIPTION]
az cosmosdb create: error: list index out of range

Any idea of what could be the cause of the error ? 知道可能是错误原因的原因吗?

I'm suspecting about this line but I'm not sure how can be specified: 我怀疑这行,但不确定如何指定:

 --locations "Central US"=0 "Central US"=0 

Yes, --locations seems to be the problem. 是的,-- --locations似乎是问题所在。 According to the doc : 根据文档

Space-separated locations in 'regionName=failoverPriority' format. 以“ regionName = failoverPriority”格式分隔的位置。 Eg eastus=0 westus=1. 例如eastus = 0 westus = 1。 Failover priority values are 0 for write regions and greater than 0 for read regions. 对于写入区域,故障转移优先级值为0,对于读取区域,故障转移优先级值大于0。 A failover priority value must be unique and less than the total number of regions. 故障转移优先级值必须唯一且小于区域总数。 Default: single region account in the location of the specified resource group. 默认值:指定资源组所在位置的单个区域帐户。

So for example, this works for configuring CentralUS as the read/write region and EastUS as a read region: 因此,例如,这适用于将CentralUS配置为读/写区域,并将EastUS配置为读区域:

--locations "CentralUS=0" "EastUS=1"

The --locations option allows you the specify the failover priority. --locations选项允许您指定故障转移优先级。

Find below an example that creates a new CosmosDB/SQL account, where East US is primary (Read-Write) and West US is secondary (Read-Only) . 在下面找到一个示例,该示例创建一个新的CosmosDB / SQL帐户,其中East US是主要帐户(读写)West US是次要帐户(只读)

az cosmosdb create --name "cosmosdb5555" --kind GlobalDocumentDB --resource-group "cosmosdbrg" --locations "eastus=0", "westus=1"

You are observing an error because the --locations you specified is invalid due to duplicated regions and syntax. 您正在观察错误,因为指定的--locations由于区域和语法重复而无效。

The following error will be thrown if you specify duplicated regions in --locations : 如果在--locations中指定重复的区域,将引发以下错误:

Operation failed with status: 'BadRequest'. Details: Failover priorities must be unique and 0 <= priority < (number of failover policies)
ActivityId: 689752f6-8081-11e8-8a4b-9cb6d00f36f2, Microsoft.Azure.Documents.Common/2.0.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM