Cedric Arnould
Cedric Arnould

Reputation: 2413

CosmosDBTrigger on Azure Function without Lease Collection

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

Upvotes: 4

Views: 3936

Answers (2)

Dillorscroft
Dillorscroft

Reputation: 253

I would suggest scaling the database rather than the collection. If you scaled the database at 400 RU/s you can share that across collections.

Upvotes: 2

Jay Gong
Jay Gong

Reputation: 23792

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.

Upvotes: 11

Related Questions