Azure Function fails with error message collection doesn’t exist
Azure Function fails with error message “Either the source collection ‘collection-name’ (in database ‘database-name’) or the lease collection ‘collection2-name’ (in database ‘database2-name’) does not exist. Both collections must exist before the listener starts. To automatically create the lease collection, set ‘CreateLeaseCollectionIfNotExists’ to ‘true'”
This means that either one or both of the Azure Cosmos containers required for the trigger to work do not exist or are not reachable to the Azure Function. The error itself will tell you which Azure Cosmos database and container is the trigger looking for based on your configuration.
- Verify the
ConnectionStringSetting
attribute and that it references a setting that exists in your Azure Function App. The value on this attribute shouldn’t be the Connection String itself, but the name of the Configuration Setting. - Verify that the
databaseName
andcollectionName
exist in your Azure Cosmos account. If you are using automatic value replacement (using%settingName%
patterns), make sure the name of the setting exists in your Azure Function App. - If you don’t specify a
LeaseCollectionName/leaseCollectionName
, the default is “leases”. Verify that such container exists. Optionally you can set theCreateLeaseCollectionIfNotExists
attribute in your Trigger totrue
to automatically create it. - Verify your Azure Cosmos account’s Firewall configuration to see to see that it’s not it’s not blocking the Azure Function.
Note: Make sure you create a collection called “leases” in your database or set the CreateLeaseCollectionIfNotExists =true
Sources:
https://docs.microsoft.com/en-us/azure/cosmos-db/troubleshoot-changefeed-functions
Comments