I have an Azure Function which is triggered each time that one on more items in my CosmosDb Collection is updated.
The code works correctly:
[StorageAccount("AzureWebJobsStorage")]
public static class ChangeFeedFunction
{
[FunctionName("ChangeFeedFunction")]
public static void ChangeFeedFunction(
[CosmosDBTrigger(
databaseName: "MyDataBase",
collectionName: "MyCollection",
ConnectionStringSetting = "CosmosDbConnectionString",
LeaseCollectionName = "MyCollection_Leases",
CreateLeaseCollectionIfNotExists = true
)] IReadOnlyList<Document> documents,
[Queue("collection-changes")] ICollector<Message> analystQueue,
ILogger logger
)
{
//Operations;
}
But in the case, it means I have 2 CosmosDb Collections (MyCollection and MyCollection_Leases) which is minimum 40$ per month. I would like to reduce the cost. Is there a way to observe the modification on my CosmosDb Collection without using another CosmosDb Collection?
Thanks
Following the cosmos db trigger function document, the lease
collection can't be avoid so far because it bears important responsibility.
We need one lease
collection when using the Trigger to store the checkpoints for each Function. Let me say that if there are 10 documents were inserted into cosmos db, the trigger function was triggered one by one and the checkpoint moved with the process and stored into lease
collection. Suddently, the trigger shut down resulted from some reasons. During this time, 5 more documents inserted into db. After the trigger function restarting, it knows from which node to continue the execution function with the checkpoint in lease
collection.(I wish I had made it clear...)
BTW,you could share one single lease
collection for all of your collection for a more cost-effective approach. Please refer to this article.
As for the cost,you could create the minimum configured lease
collection. And the cost on the portal is estimated value. The price based on the consumption of RUs. Please refer to this document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With