Azure 函数触发器不适用于 cosmosdb 的不同资源 ID

Azure Function Trigger not working for a different resource id of cosmosdb

我正在尝试创建一个 azure 函数 cosmosdbtrigger。与我的 azure 函数相比,我的 cosmosdb 位于不同的资源 ID 中。但是我的功能没有被触发。

azure function和cosmosdb在同一个resource id中有什么限制吗?如果没有,是否需要为不同的资源 ID 进行任何其他设置。

我的 azure 函数在 python 运行 linux 应用服务上。从我了解到的 azure 文档中,我不能将来自 windows 和 linux 的应用程序服务混合作为当前限制。

Azure Documentation on Current Limitation

我需要使用 azure 函数 Python 来检查 azure cosomos db 更改提要。

这是我的 function.json 用于连接到 cosmosdb 收集触发器..

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "documents",
      "direction": "in",
      "leaseCollectionName": "leases1",
      "connectionStringSetting": "devcosmosdb_DOCUMENTDB",
      "databaseName": "devcosmosdb",
      "collectionName": "testCollection",
      "createLeaseCollectionIfNotExists": "true"
    }
  ]
}

没有这样的限制。

请再次检查 databaseNamecollectionNameconnectionStringSetting

如果您已经将函数部署到 Azure 门户。您需要将 connectionStringSetting 添加到应用程序设置。在您的场景中,您应该像这样添加 connectionString

您可以在您的 cosmosdb 帐户的 Keys 部分下找到 connectionString。

此外,请检查 FireWall 设置。

我想补充一些与此主题相关的更有用的信息。当您使用 __init__.py 的默认模板将插入的文档更新到您的 CosmosDB 时,您可能是查看监视器日志等待出现某些内容的老我。

我可以向您推荐这个 link - https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-configure-cosmos-db-trigger#enabling-logging

您需要编辑 host.json 文件以启用 CosmosDB 的日志记录,然后任何有用的内容才会出现在您的日志中。

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "Host.Triggers.CosmosDB": "Trace"
    }
  }
}