"Can't figure out which ctor to call." error with CosmosDB trigger
I'm trying to run a new Function locally. It uses the CosmosDB trigger. Building works fine, but when trying to run with func host start, I get this error: The 'companiesWrite' function is in error: Unable to configure binding 'cosmosDBTrigger1' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.
I see a similar issue here: https://github.com/Azure/Azure-Functions/issues/277. The problem was a misnamed configuration property. But I checked all of mine against both the TypeScript def and the online documentation.
My code:
import { app, InvocationContext } from "@azure/functions";
export async function companiesWrite(documents: any[], context: InvocationContext): Promise<void> {
context.log(`Cosmos DB function processed ${documents.length} documents`);
}
app.cosmosDB('companiesWrite', {
connectionStringSetting: 'devworksafetyindex_DOCUMENTDB',
databaseName: 'wsi',
collectionName: 'companies',
createLeaseCollectionIfNotExists: true,
maxItemsPerInvocation: 40,
handler: companiesWrite
});
My host.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
I tried adding an HttpTrigger Function, and this worked fine. So it appears to be something specific to my CosmosDB trigger.
Thanks!
thanks for reporting please share the repro steps.
have you properly used local setting.json file like azurewebjob storage etc.
Yep, local.settings.json is properly configured. I used the wizard to walk through the process.
Reproduction steps (in VS Code):
- Ctrl + Shift + P > Azure Functions: Create Function...
- Azure Cosmos DB trigger
- Provide name
- Create new local app settings
- Enter DB name
- Enter container name
- Automatically create lease collection if not exists (true)
The Azure Functions extension does the rest. I did check both my local.settings.json file and my configuration params, and it all seems correct.
@bhagyshricompany See comment above.
I'm facing the same issue. Creating a brand new Azure Function CosmosDB trigger via the VS Code extension generates this error on function start.
Same issue, via VS Code
it seems that you need to add 'connection' and 'containerName' instead of connectionStringSetting and collectionName, if you dont the Options probably get recognized as v3Options instead of v4options.
it seems that you need to add 'connection' and 'containerName' instead of connectionStringSetting and collectionName, if you dont the Options probably get recognized as v3Options instead of v4options.
@mattonecz is right, VSCode template is just using the wrong key names. For working V4 names, check Configuration
Nice. This got me past my error.
I guess the request here then is to update the VS Code template.
It would also be nice if the Model version was more obvious somehow. Just looking through my config, I'm not sure how I'd know that I should be using Model v4 over v3.
This issue still persists with the latest Azure Functions Core Tools updated in VisualStudio Code Insiders, and following all the default prompts to create an Azure Cosmos DB Trigger function. using JavaScript, Model V4.
The template still creates with Incorrect CosmosDBv3TriggerOptions, and not the correct CosmosDBv4TriggerOptions
Thus I need to Edit
connectionStringSetting:
collectionName:
createLeaseCollectionIfNotExists:
to the V4 names:
connection:
containerName:
createLeaseContainerIfNotExists:
This has fortunately been pointed out above, and saved me lots of time. This is so unfortunate, as otherwise fantastic to use.