Failed to create a record in Azure CosmoDB through Azure function according to "Exercise - Write data with output bindings" lesson in Azure developer certificate

Nguyen Minh Thong 0 Reputation points
2023-10-29T10:36:03.6633333+00:00

I am implementing the lesson "Exercise - Write data with output bindings" in Azure learn in terms of Azure developers but i am stuck with the output binding of Azure CosmoDB. It keeps logging the bugs: "2023-10-29T10:20:44.745 [Error] Executed 'Functions.HttpTrigger2' (Failed, Id=efaeece6-b2bd-4f1c-b0dd-a5a93e273f70, Duration=466ms)Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: ca41cc79-f422-49cd-a3bb-b32e515427e7; Reason: (code : NotFoundmessage : Entity with the specified id does not exist in the system. More info: https://aka.ms/cosmosdb-tsg-not-found,RequestStartTime: 2023-10-29T10:20:44.3630919Z, RequestEndTime: 2023-10-29T10:20:44.3847311Z, Number of regions".

my js file is according to the file in the lesson: https://learn.microsoft.com/en-us/training/modules/chain-azure-functions-data-using-bindings/7-write-data-with-output-bindings-portal-lab?pivots=javascript

Here is my function.js file:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "name": "bookmark",
      "direction": "in",
      "type": "cosmosDB",
      "connection": "tommycosmobb_DOCUMENTDB",
      "databaseName": "func-io-learn-db",
      "containerName": "Bookmarks",
      "id": "{id}",
      "partitionKey": "{id}"
    },
    {
      "name": "newbookmark",
      "direction": "out",
      "type": "cosmosDB",
      "connection": "tommycosmobb_DOCUMENTDB",
      "databaseName": "func-io-learn-db",
      "containerName": "Bookmarks",
      "partitionKey": "/id"
    },
    {
      "name": "newmessage",
      "direction": "out",
      "type": "queue",
      "connection": "tommylab8a65_STORAGE",
      "queueName": "bookmarks-post-process"
    }
  ]
}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,345 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,738 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Mike Urnun 9,831 Reputation points Microsoft Employee
    2023-10-31T20:45:21.1566667+00:00

    Hello, @Nguyen Minh Thong - Could you make sure that there is an actual matching item in the CosmosDB and try again? The correct expression for the "id" and "partitionKey" is {id} for both input and output bindings.

    The tutorial seems to have gone a bit out of date on this aspect of the configuration or could probably communicate the configuration and its common pitfalls better. Based on the issues surrounding this tutorial that were reported in the past (which are listed at the bottom of this answer), the Notfoundmessage error is caused by the following two factors:

    • The actual matching item not being present in the CosmosDB. This should typically be handled gracefully in the solution without throwing runtime errors.
    • Binding configuration, specifically between containerName vs collectionName, may vary depending on the version of Functions runtime/CosmosDB Extension version you're using. Please review the Azure Cosmos DB trigger for Azure Functions 2.x and higher doc thoroughly for the right configuration for your setup.

    Similar posts:


    Please "Accept Answer" if the answer is helpful so that others in the community may benefit from your experience.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.