AZ204 Developer challenge on Module4 name: Chain Azure Functions together using input and output bindings

rdp 0 Reputation points
2024-05-15T01:34:51.84+00:00

When I was working on the Azure Function's

Module name: Chain Azure Functions together using input and output bindings

I got an error only after adding the output bindings.

Error message:

2024-05-02T16:44:00.267 [Error] Executed 'Functions.HttpTrigger3' (Failed, Id=3adfe2ef-2c11-411c-ab66-46371138cc42, Duration=10ms)Cosmos DB connection configuration 'CosmosDB' does not exist. Make sure that it is a defined App Setting.

To resolve it, In Function's environment variable, had only two values namely AccountEndpoint and AccountKey. But later I added 2 more values as well namely, Database value and containerId.

AccountEndpoint=https://<accountname>.documents.azure.com:443/;AccountKey=<key>;

Database=func-io-learn-db;containerId=Bookmarks;

After restarting the function, following was the error message,

New Error Message: 2024-05-02T17:37:01.582 [Error] Executed 'Functions.HttpTrigger3' (Failed, Id=6241cece-4917-4180-aa78-257c4427133b, Duration=10ms)Value cannot be null. (Parameter 'containerId')

Furthermore, following was function.json 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",

  "partitionKey": "{id}",

  "methods": [],

  "databaseName": "func-io-learn-db",

  "collectionName": "Bookmarks",

  "connectionStringSetting": "azcosmosdbaccount1_DOCUMENTDB",

  "id": "{id}"

},

{

  "name": "newbookmark",

  "direction": "out",

  "type": "cosmosDB",

  "partitionKey": "/id",

  "methods": [],

  "databaseName": "func-io-learn-db",

  "collectionName": "Bookmarks",

  "connectionStringSetting": "azcosmosdbaccount1_DOCUMENTDB"

},

{

  "name": "newmessage",

  "direction": "out",

  "type": "queue",

  "queueName": "bookmarks-post-process",

  "methods": [],

  "connection": "learn72620e65a50a4980b5_STORAGE"

}
```  ]

}

I went through the post and made the necessary changes. But the error message did not change. Any help would be greatly appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,678 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Gowtham CP 3,730 Reputation points
    2024-05-15T05:57:35.3333333+00:00

    Hello rdp,

    Thanks for reaching out in the Microsoft Q&A!

    To resolve the error "Value cannot be null" for the parameter 'containerId' in your Azure Functions Cosmos DB output binding, ensure that you provide a valid value for the partitionKey parameter in the output binding configuration. In your function.json file, specify the partition key as below:

    {
      "name": "newbookmark",
      "direction": "out",
      "type": "cosmosDB",
      "partitionKey": "/yourPartitionKeyField", // specify the partition key here
      "methods": [],
      "databaseName": "func-io-learn-db",
      "collectionName": "Bookmarks",
      "connectionStringSetting": "azcosmosdbaccount1_DOCUMENTDB"
    }
    
    

    Now you should be able to resolve the "Value cannot be null" error in your Azure Function.Don't forget to upvote! If you found this solution helpful, consider accepting it.