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
2
Answers
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).
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.
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.