简体   繁体   English

使用 Cosmos DB 绑定从 Azure 函数执行 Cosmos DB 服务器端触发器

[英]Execute a Cosmos DB server-side trigger from an Azure function using Cosmos DB bindings

I have an Azure function using a Cosmos DB trigger written in Python that has both IN and OUT bindings to Cosmos DB so when a document is updated in the container I create a new document in another container.我有一个使用 Python 编写的 Cosmos DB 触发器的 Azure 函数,该触发器具有与 Cosmos DB 的 IN 和 OUT 绑定,因此当容器中的文档更新时,我会在另一个容器中创建一个新文档。 I want to create a server-side Cosmos DB trigger inside the second container that needs to be triggered when the new document is created.我想在创建新文档时需要触发的第二个容器内创建一个服务器端 Cosmos DB 触发器。 In the examples I have seen they show how to use the Python SDK to execute the trigger but I wanted to know if it is possible to use the bindings I already have in the function to execute the trigger rather than including the Azure Cosmos library into my function.在我看到的示例中,他们展示了如何使用 Python SDK 执行触发器,但我想知道是否可以使用函数中已有的绑定来执行触发器,而不是将 Azure Cosmos 库包含到我的功能。 The SDK example shows container.create_item(item, {'post_trigger_include': 'trgPreValidateToDoItemTimestamp'}) to execute the trigger, but I was hoping there was a similar option for the "set" method used in an Azure function binding to create a new document (like container.set(doc,{'post_trigger_include': 'trgPreValidateToDoItemTimestamp'}) ) but that doesn't work. SDK 示例显示container.create_item(item, {'post_trigger_include': 'trgPreValidateToDoItemTimestamp'})来执行触发器,但我希望 Azure 函数绑定中使用的“set”方法有一个类似的选项来创建一个新的文档(如container.set(doc,{'post_trigger_include': 'trgPreValidateToDoItemTimestamp'}) ),但这不起作用。

Short answer is no.简短的回答是否定的。

The Azure Functions bindings are exposed through generic interfaces (all bindings have the same) so it does not allow for extra input parameters. Azure Functions 绑定通过通用接口公开(所有绑定都相同),因此它不允许额外的输入参数。

If your Function ran on .NET one alternative is to use the Binding to access the client instance and use the client instance to execute the operation instead of the Binding interface: https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=in-process%2Cfunctionsv2&pivots=programming-language-csharp#http-trigger-get-multiple-docs-using-documentclient-c如果您的 Function 在 .NET 上运行,另一种方法是使用 Binding 访问客户端实例并使用客户端实例而不是 Binding 接口执行操作: https ://docs.microsoft.com/azure/azure-functions/ functions-bindings-cosmosdb-v2-input?tabs=in-process%2Cfunctionsv2&pivots=programming-language-csharp#http-trigger-get-multiple-docs-using-documentclient-c

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

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