#Building Backend - Azure Function - 500 (Internal Server Error)

10 messages · Page 1 of 1 (latest)

steady trench
#

Hello All,
I managed to set up CosmosDB and Azure Function HTTP Trigger in Javascript with Binding input/output. Azure Function is trigger by entering on my website but it is resulting with an error which I found in Application Insight.

Error:
Exception while executing function: Functions.HttpTrigger1 Cosmos DB connection configuration 'CosmosDB' does not exist. Make sure that it is a defined App Setting.

I created connection between Function and CosmosDB.

Below Function.json code
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "inputDocument",
"databaseName": "ToDoList",
"collectionName": "Items",
"connectionStringSetting": "db-cosmos_DOCUMENTDB",
"direction": "in",
"type": "cosmosDB"
},
{
"name": "outputDocument",
"databaseName": "ToDoList",
"collectionName": "Items",
"connectionStringSetting": "db-cosmos_DOCUMENTDB",
"direction": "out",
"type": "cosmosDB"
}
]
}

I hoping for help or any advice. Thank you.

steady trench
#

update:
has been fixed by myself. I have runtime V4 and I was using code for V3 runtime.
What I did, I updated properties in function.json, namely V3 is using connectionStringSetting and in V4 we need to use connection. Same for collectionName, we need to change for containerName to be compatible with V4 runtime.

steady trench
#

after adjustments, azure functions is working and correctly adding data to cosmosDB

glossy gyro
#

Where did you need to fix the function.json? I have added the connectionString in configuration but I'm still getting the same Internal Error - saying that the CosmosDB doesn't exist

steady trench
#

@glossy gyro in the Http trigger - function.json

glossy gyro
#

Yep I've updated that but its still not working on mine.

#

Ooh, but now I have a different error message!

steady trench
#

what error message do you have now?

glossy gyro
#

First it wasn’t recognising “count” so I think I need to relook at my function. But my eyes are falling out of my head now and I need to go to sleep 😤🥱😴 I’ll try again tomorrow!