我为 cosmosDB 触发器创建了一个独立的 Azure 函数。我正在使用 Microsoft.Azure.Functions.Worker.Extensions.CosmosDB --version 4.0.0-preview2 来使用托管标识。下面是我的功能。
[Function("CosmosDBTrigger")]
public void Run([CosmosDBTrigger(
databaseName: "testdata",
containerName: "test",
Connection = "connect",
LeaseContainerName = "leases")] IReadOnlyList<MyDocument> input)
{}
本地.settings.json
{
"Values": {
connect__accountEndpoint": "https://testdatacosmosdb.documents.azure.com:443/"
}}
我收到错误“Cosmos DB 连接配置‘连接’不存在。请确保它是已定义的应用程序设置。我不确定是否由于孤立的 Azure 函数而发生这种情况
您缺少凭据。看:
- https://learn.microsoft.com/azure/azure-functions/functions-reference?tabs=cosmos#common-properties-for-identity-based-connections
所有要使用 MSI 的 Azure Functions 绑定都需要<your attribute value>__credential
除了服务特定属性之外的配置中。
对于 Cosmos DB,服务特定属性是accountEndpoint
.
总而言之,您需要两者兼而有之。
In your local.settings.json
file:
{
"connect" : {
"accountEndpoint": "https://testdatacosmosdb.documents.azure.com:443/",
"credential" : "managedidentity"
}
}
在 Azure 中部署后,您需要将它们添加到您的功能 应用程序配置,为此您可以使用下划线符号:
您使用的包版本较旧,仅支持在 Function App 配置的“连接字符串”部分添加这些内容。
"connect__accountEndpoint": "https://testdatacosmosdb.documents.azure.com:443/"
"connect__credential": "managedidentity"
这也是整个场景从头到尾的 Azure Friday 片段:https://www.youtube.com/watch?v=w002dYaP9mw
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)