Azure Cosmos DB Input bindings come with incorrect fields on Azure Portal
When you create an Azure Cosmos DB Input in your function on Azure Portal, the template generates a binding with incorrect fields like connectionStringSetting and collectionName which should be connection and containerName.
Investigative information
- Timestamp: 2023-09-24T13:38:46.408
- Function App version: 4.26.1.21286
- Function App name: week3-coursera
- Function name(s) (as appropriate): HttpTrigger1
- Invocation ID: e64eb6c0-1575-41a6-a145-5042ba4db216
- Region: Germany West Central
Repro steps
Provide the steps required to reproduce the problem:
- Sign in to Azure Portal
- Create an Azure Cosmos DB Account
- Create a new Azure Cosmos DB Container
- Create a Function App
- Create an HTTP Trigger Function
- Navigate to Integrations tab in your function
- Add a CosmosDB Input
- Open file logs
- Try to get data from CosmosDB using the function
- Observe the error log that says:
Cosmos DB connection configuration 'CosmosDB' does not exist. Make sure that it is a defined App Setting.
Or you can simply follow this guide on Microsoft Learn as newly created CosmosDB bindings are faulty right now: https://learn.microsoft.com/en-us/training/modules/chain-azure-functions-data-using-bindings/5-read-data-with-input-bindings-portal-lab?pivots=javascript
Expected behavior
The function should be able to connect to Azure Cosmos DB.
Actual behavior
The function does not connect to Azure Cosmos DB and throws the following error:
Cosmos DB connection configuration 'CosmosDB' does not exist. Make sure that it is a defined App Setting.
Known workarounds
You can manually change the field names in bindings as below:
- Change
connectionStringSettingtoconnection - Change
collectionNametocontainerName
Related information
Provide any related information
- Programming language used Javascript
- Links to source https://learn.microsoft.com/en-us/training/modules/chain-azure-functions-data-using-bindings/5-read-data-with-input-bindings-portal-lab?pivots=javascript
- Bindings used Azure CosmosDB Input
Source
Bindings
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "documentUrls",
"direction": "in",
"type": "cosmosDB",
"connectionStringSetting": "####_DOCUMENTDB",
"databaseName": "new-database",
"collectionName": "new-container",
"id": "{id}",
"partitionKey": "/id"
}
]
}
Code
module.exports = function (context, req) {
var bookmark = context.bindings.bookmark
if(bookmark){
context.res = {
body: { "url": bookmark.url },
headers: {
'Content-Type': 'application/json'
}
};
}
else {
context.res = {
status: 404,
body : "No bookmarks found",
headers: {
'Content-Type': 'application/json'
}
};
}
context.done();
};
Thanks for update.Can you try this and check its working.{ "bindings": [ { "authLevel": "function", "name": "req", "type": "httpTrigger", "direction": "in", "methods": [ "get", "post" ] }, { "name": "$return", "type": "http", "direction": "out" }, { "name": "outputDocument", "direction": "out", "type": "cosmosDB", "connection": "afreen-cosmosdb_DOCUMENTDB", "databaseName": "outDatabase", "containerName": "MyCollection", "createIfNotExists": true, "partitionKey": "/id" } ] }
Thanks @bhagyshricompany for your response. I am aware of the workaround, I already mentioned it twice in the issue. I opened this issue to report a bug.
I am experiencing the same issue on Azure Cosmos DB Output bindings resulting in "Cosmos DB connection configuration 'CosmosDB' does not exist. Make sure that it is a defined App Setting."
The mentioned workaround of renaming the field names does not work since they are reverted automatically.
Thank you so much @mburakeker The microsoft documentation is super careless. https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cextensionv4&pivots=programming-language-javascript#http-trigger-look-up-id-from-route-data-javascript
databaseName: 'ToDoItems',
collectionName: 'Items',
id: '{id}',
partitionKey: '{partitionKeyValue}',
connectionStringSetting: 'CosmosDBConnection',
instead of
databaseName: "ToDoItems", containerName: "Items", id: "{id}", partitionKey: "{partitionKeyValue}", connection: "CosmosDBConnection",