0

I am upgrading an existing Function App into v4 runtime.

I'm running and testing it locally via venv.

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "documents",
      "direction": "in",
      "leaseCollectionName": "leases2",
      "connectionStringSetting": "AzureWebJobsCosmosDBConnectionString",
      "databaseName": "%DBNameFromKeyVault%",
      "collectionName": "%CollectionNameFromKeyVault%",
      "createLeaseCollectionIfNotExists": true
    }
  ]
}

local.settings.json

{
    "IsEncrypted": false,
    "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true"
   
    }
  }
  

i have install what on requirements.txt.

pip install -r requirements.txt

then func start

and i got an error: The 'myfunction' function is in error: Unable to configure binding 'documents' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.

This is Azure Functions Core Tools versionL Core Tools Version: 4.0.5198 Commit hash: N/A (64-bit) Function Runtime Version: 4.21.1.20667

I have also did func extension install. it was installed successfully.

My expectation, since I'm only upgrading the function app from v2 to v4, there's no changes in code except for the versions from the requirements.txt, extensions, and runtime.

Do i miss anything? Hope you can help me. Thank you.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
iamrhass
  • 1
  • 2
  • 1
    You might need to use `createLeaseContainerIfNotExists` etc? https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger?tabs=python-v2%2Cin-process%2Cextensionv4&pivots=programming-language-python#configuration the name of most of the settings changed – Martin Smith Jul 25 '23 at 12:37
  • Thank you for this! I have changed it and it removed the error. Thank you. – iamrhass Aug 09 '23 at 04:09

1 Answers1

0

I have reproduced this issue at my environment and able to get the expected results

Here I am using below versions alike you

Azure Functions Core Tools
Core Tools Version:       4.0.5198 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.21.1.20667

I am also fetching the database name and collection name from Key vault.

function.json:

{
"scriptFile": "__init__.py",
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leasesDemo",
"connectionStringSetting": "afreencosmosdb_DOCUMENTDB",
"databaseName": "%DBNameFromKeyVault%",
"collectionName": "%CollectionNameFromKeyVault%",
"createLeaseCollectionIfNotExists": true
}
]
}

local.settings.json:

{

"IsEncrypted": false,
"Values": {  
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python",
"afreencosmosdb_DOCUMENTDB": "<Your cosmos DB connection string>",
"DBNameFromKeyVault": "@Microsoft.KeyVault(SecretUri=<your db name link created in secrets>)",
"CollectionNameFromKeyVault": "@Microsoft.KeyVault(SecretUri=<your collection link created in secrets>)"

}
}

Try to add the missing details in your local.settings.json file like cosmos DB connection string and the database name and the collection name which you are referring from key vault.

As suggested in this SO Thread, your issue will get resolved after adding the above parameters in your local setting file.

host.json:

{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
}
}

requirement.txt:

azure-functions

Output:

enter image description here

Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6
  • Thank you for this! I was able to solve the error on binding. But another error came up though I think its not related on binding. – iamrhass Aug 09 '23 at 04:12