在 Azure 中获取 CosmosDB 的连接字符串时出现问题
Problem to get a connectionString for CosmosDB in Azure
我正在效仿这个例子:
https://github.com/Azure-Samples/java-functions-eventhub-cosmosdb
但是当我尝试使用 Azure CLI 获取 connectionString 时,我收到以下错误:
COSMOS_DB_CONNECTION_STRING=$( \
az cosmosdb keys list \
--resource-group $RESOURCE_GROUP \
--name $COSMOS_DB_ACCOUNT \
--type connection-strings \
--query connectionStrings[0].connectionString \
--output tsv)
来自az
的错误信息:
no matches found: connectionStrings[0].connectionString
有什么帮助吗?
非常感谢
az --version
azure-cli 2.2.0
command-modules-nspkg 2.0.3
core 2.2.0
nspkg 3.0.4
telemetry 1.0.4
Extensions:
azure-cli-iot-ext 0.8.9
application-insights 0.1.4
Python location '/usr/local/Cellar/azure-cli/2.2.0_1/libexec/bin/python'
Extensions directory '/Users/juan.brena/.azure/cliextensions'
Python (Darwin) 3.8.2 (default, Mar 11 2020, 00:29:50)
[Clang 11.0.0 (clang-1100.0.33.17)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
显示当前连接字符串的示例:
az cosmosdb keys list \
--resource-group $RESOURCE_GROUP \
--name $COSMOS_DB_ACCOUNT \
--type connection-strings
输出:
{
"connectionStrings": [
{
"connectionString": "AccountEndpoint=xxx",
"description": "Primary SQL Connection String"
},
{
"connectionString": "AccountEndpoint=xxx",
"description": "Secondary SQL Connection String"
},
{
"connectionString": "AccountEndpoint=xxx",
"description": "Primary Read-Only SQL Connection String"
},
{
"connectionString": "AccountEndpoint=xxx",
"description": "Secondary Read-Only SQL Connection String"
}
]
}
思路是获取第一个connectionString:
{
"connectionString": "AccountEndpoint=xxx",
"description": "Primary SQL Connection String"
}
试试这个。
RESOURCE_GROUP='myResourceGroup'
COSMOS_DB_ACCOUNT='my-cosmos-account'
COSMOS_DB_CONNECTION_STRING=$(az cosmosdb keys list \
-g $RESOURCE_GROUP \
-n $COSMOS_DB_ACCOUNT \
--type connection-strings \
--query connectionStrings[0].connectionString \
--output tsv)
echo $COSMOS_DB_CONNECTION_STRING
我在我的 ubuntu devcontainer 中遇到了同样的问题,并且能够通过将查询包含在 单引号 :
中来解决它
az cosmosdb keys list \
--name $ACCOUNTNAME \
--resource-group $RESOURCEGROUP \
--type connection-strings \
--query 'connectionStrings[0].connectionString' \
--output tsv
我正在效仿这个例子: https://github.com/Azure-Samples/java-functions-eventhub-cosmosdb
但是当我尝试使用 Azure CLI 获取 connectionString 时,我收到以下错误:
COSMOS_DB_CONNECTION_STRING=$( \
az cosmosdb keys list \
--resource-group $RESOURCE_GROUP \
--name $COSMOS_DB_ACCOUNT \
--type connection-strings \
--query connectionStrings[0].connectionString \
--output tsv)
来自az
的错误信息:
no matches found: connectionStrings[0].connectionString
有什么帮助吗?
非常感谢
az --version
azure-cli 2.2.0
command-modules-nspkg 2.0.3
core 2.2.0
nspkg 3.0.4
telemetry 1.0.4
Extensions:
azure-cli-iot-ext 0.8.9
application-insights 0.1.4
Python location '/usr/local/Cellar/azure-cli/2.2.0_1/libexec/bin/python'
Extensions directory '/Users/juan.brena/.azure/cliextensions'
Python (Darwin) 3.8.2 (default, Mar 11 2020, 00:29:50)
[Clang 11.0.0 (clang-1100.0.33.17)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
显示当前连接字符串的示例:
az cosmosdb keys list \
--resource-group $RESOURCE_GROUP \
--name $COSMOS_DB_ACCOUNT \
--type connection-strings
输出:
{
"connectionStrings": [
{
"connectionString": "AccountEndpoint=xxx",
"description": "Primary SQL Connection String"
},
{
"connectionString": "AccountEndpoint=xxx",
"description": "Secondary SQL Connection String"
},
{
"connectionString": "AccountEndpoint=xxx",
"description": "Primary Read-Only SQL Connection String"
},
{
"connectionString": "AccountEndpoint=xxx",
"description": "Secondary Read-Only SQL Connection String"
}
]
}
思路是获取第一个connectionString:
{
"connectionString": "AccountEndpoint=xxx",
"description": "Primary SQL Connection String"
}
试试这个。
RESOURCE_GROUP='myResourceGroup'
COSMOS_DB_ACCOUNT='my-cosmos-account'
COSMOS_DB_CONNECTION_STRING=$(az cosmosdb keys list \
-g $RESOURCE_GROUP \
-n $COSMOS_DB_ACCOUNT \
--type connection-strings \
--query connectionStrings[0].connectionString \
--output tsv)
echo $COSMOS_DB_CONNECTION_STRING
我在我的 ubuntu devcontainer 中遇到了同样的问题,并且能够通过将查询包含在 单引号 :
中来解决它az cosmosdb keys list \
--name $ACCOUNTNAME \
--resource-group $RESOURCEGROUP \
--type connection-strings \
--query 'connectionStrings[0].connectionString' \
--output tsv