The 'CosmosDBTrigger' function is in error: Unable to configure binding 'documents' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
I'm trying to run my CosmosDB trigger locally, but when trying to run with func host start, I get this error: **The 'CosmosDBTrigger' function is in error: Unable to configure binding 'documents' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.**
I found a similar issue here: #2447, but even after trying the suggested solution and using the sample code from the Azure CosmosDB trigger documentation, I couldn't resolve it.
Here are my files:
**function_app.py**
```python
import logging
import os
import azure.functions as func
from main import app as main
import logging
import azure.functions as func
app = func.AsgiFunctionApp(app=main, http_auth_level=func.AuthLevel.ANONYMOUS)
@app.function_name(name="CosmosDBTrigger")
@app.cosmos_db_trigger(
arg_name="documents",
database_name="",
collection_name="",
create_if_not_exists=True,
lease_container_name="leases",
create_lease_container_if_not_exists="true",
connection_string_setting=os.getenv("COSMOS_DB_CONNECTION_STRING"))
def test_function(documents: func.DocumentList) -> str:
if documents:
logging.info('Document id: %s', documents[0]['id'])
```
**host.json**
```
{
"version": "2.0",
"extensions": {
"http": {
"routePrefix": ""
},
"cosmosDB": {
"connectionMode": "Gateway",
"userAgentSuffix": "cosmostest"
}
},
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
```
**local.setting.json**
```{
"IsEncrypted": false,
"Values": {
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=;AccountKey=EndpointSuffix=core.windows.net",
"FUNCTIONS_WORKER_RUNTIME": "python",
"_DOCUMENTDB": "AccountEndpoint=https://.documents.azure.com:443/;AccountKey="
}
}
```
**function.json**
```{
"scriptFile": "function_app.py",
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "azcosmosdb",
"direction": "in",
"collectionName": "",
"databaseName": "",
"connectionStringSetting": "_DOCUMENTDB",
"leaseCollectionName": "leasesDemo",
"createLeaseCollectionIfNotExists": true
},
{
"type": "httpTrigger",
"name": "req",
"direction": "in",
"authLevel": "anonymous"
},
{
"type": "http",
"name": "res",
"direction": "out"
}
]
}
```
Just want the trigger to run whenever there is any CRUD operation in Cosmos DB, that's all.
Thanks!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.