question

JonathanGriffiths-2589 avatar image
5 Votes"
JonathanGriffiths-2589 asked DonDexter-5224 answered

Silent failure of Azure Function CosmosDB input binding

I have been following the exercise at this URL ...
https://docs.microsoft.com/en-us/learn/modules/chain-azure-functions-data-using-bindings/5-read-data-with-input-bindings-portal-lab?pivots=javascript

... and everything is OK until I get to the "Try it out" section at the end, at which point the function always returns "No bookmarks found", irrespective of what value I supply for the id parameter.

The logs for the Azure Function App all show the function executing successfully. However, the activity log on the CosmosDB side shows no activity, as if the database had not even been contacted.

Just to be clear, the code of the function (in index.js) is copied directly from the exercise instructions, and the function.json is as follows, (where jgfunctioniotestse is the name of my CosmosDB account). Also, the CosmosDB contains the five items indicated in the exercise (in database "func-io-learn-db", container "Bookmarks".

{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "bookmark",
"direction": "in",
"type": "cosmosDB",
"databaseName": "func-io-learn-db",
"collectionName": "Bookmarks",
"connectionStringSetting": "jgfunctioniotestse_DOCUMENTDB",
"id": "id",
"partitionKey": "/id"
}
]
}

This absence of error messages is making it hard to troubleshoot; can you suggest anywhere else I could look?

azure-functionsazure-cosmos-db
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @JonathanGriffiths-2589 , Thank you for reaching out. I am currently working on the issue faced, I will share my updates soon.

0 Votes 0 ·
AndrewMcMahon-1998 avatar image
9 Votes"
AndrewMcMahon-1998 answered HansGunnarVold-6805 edited

@JonathanGriffiths-2589 looks like theres a conflict in the docs, would only work for me by updating the doc ID and partition key to {id}.

https://stackoverflow.com/a/67135095

so values in function.json look like:

{
    ...
    "id": "{id}",
    "partitionKey": "{id}",
    ...
}


Hopefully that helps, but clarification from @ChaitanyaNaykodiMSFT-9638 on whether the docs are incorrect or the input panel is generating the wrong structure would be great!


Cheers!

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you very much for this, @AndrewMcMahon-1998

Your suggestion does work, and allows me to complete the exercise successfully, which is a big help.

However, before I mark this as the answer, my original question was about not just the failure itself but the silence of the failure: I could not find an error message anywhere to lead me to the problem. I checked the log files in \Home\LogFiles, in \Home\LogFiles\Application\Functions\Function[name of function] and in \Home\LogFiles\Host. I also looked, in the portal, at the log of activity in my CosmoDB account, and none of these places indicated anything wrong.

Something, somewhere, must have been rejecting the original "id" without {} as being malformed. So, where did it send the error? Is there a different place I need to look, or is there some configuration I need to add, to find it?

Thank you again.

8 Votes 8 ·

Thanks a bunch!

Very strange bug or remnant of something this one!
Would think they'd update either the tutorial or align the function input parameters with how the rest of the configuration works.
Alt least a heads up in the input panel would help.

partitionKey is clearly on the form "/id" for output to Cosmos DB, so the most logical thing would be the same on input.

And I agree, the scariest thing is that it all seems to run without a hitch - no error messages whatsoever.

Anything to share @ChaitanyaNaykodiMSFT-9638?

1 Vote 1 ·
ChineduOparaAssurant avatar image
3 Votes"
ChineduOparaAssurant answered ChineduOparaAssurant edited

I encountered this same problem, and found the answer on this page. Thanks to the OP for posting, and thanks @AndrewMcMahon-1998 for posting a quick solution!

Now if only Microsoft Learning team would fix this certification training material...

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MatthewHeaney-5810 avatar image
1 Vote"
MatthewHeaney-5810 answered

Likewise thanks for the solution/workaround.

This is very frustrating. The exercise literally says "Partition key = /id (slash id; NOT curly brackets or any combination of curly brackets and slashes)". Find myself none wiser moving forward




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DonDexter-5224 avatar image
0 Votes"
DonDexter-5224 answered

Holy hell, thank you!. Been struggling with this lesson for over a day - this was the last broken bit.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.