0

I am following some tutorial to connect Azure Function to Cosmosdb like this (the tutorial is for a V3 in-process azure function)

 [CosmosDBTrigger(databaseName: "Test",
            collectionName: "collection1",
            ConnectionStringSetting = "ConnectionString",
            LeaseCollectionName = "lease",                
            LeaseCollectionPrefix = "UpdateLocation-",
            CreateLeaseCollectionIfNotExists = true)]

However, with my Azure Function V4 dotnet Isolated - I have similar settings but I keep getting this error

Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.UpdateCustomerVoucherList'. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection Information for Vouchers in database Vouchers with lease leases in database Vouchers : Unable to resolve app setting for property 'CosmosDBTriggerAttribute.ConnectionStringSetting'. Make sure the app setting exists and has a valid value. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Unable to resolve app setting for property 'CosmosDBTriggerAttribute.ConnectionStringSetting'. Make sure the app setting exists and has a valid value.

I have the ConnectionString app settings in the local.settings.json and it is being used by my other http trigger function happily to insert/update the entity.

"ConnectionString": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5...."

Any ideas what else I need to do the connect dotnet isolated V4 azure function to cosmos change feed to listen to the updates.

TIA

Robert Dinaro
  • 508
  • 3
  • 8
  • 23

2 Answers2

0

Can you try the below?

In local.settings.json enter the "AccountEndpoint=..." string and give it a name. For example test_COSMOSDB

Run it locally in VS Code & make sure it's working / you can connect to CosmosDB.

the go to the Azure Portal -> Functions and enter the exact same key (test_COSMOSDB) and exact same "AccountEndpoint=..." value in Application settings for the given Function.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • but is it not the same thing as what I already have? as in "ConnectionString": "AccountE..." Do you mind explaining bit more if you mean something different. thanks – Robert Dinaro Oct 06 '22 at 08:49
  • 1
    i think you have found the problem, yes whatever you have pasted in the answer is mine. – Sajeetharan Oct 07 '22 at 04:19
0

In the end, it was very simple. For some reason the ConnectionString for cosmos which is used for Cosmos DB Trigger needs to be defined within the environment variable section of the appsettings (local.settings.json).

 "Values": {
  "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
  "FUNCTIONS_WORKER_RUNTIME_VERSION": "~4",
  "ConnectionString": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6y..."
 },

I originally had it in the section below with other AppSettings. Thats it. 2 developer days gone just to move this appsettings 2 lines up :)

Thanks everyone for trying to help.

Robert Dinaro
  • 508
  • 3
  • 8
  • 23