1

I created an isolated Azure functions for cosmosDB trigger. I'm using Microsoft.Azure.Functions.Worker.Extensions.CosmosDB --version 4.0.0-preview2 to use managed identity. Below is my function.

[Function("CosmosDBTrigger")]
    public void Run([CosmosDBTrigger(
        databaseName: "testdata",
        containerName: "test",
        Connection = "connect",
        LeaseContainerName = "leases")] IReadOnlyList<MyDocument> input)
    {}

local.settings.json

{
  "Values": {
   connect__accountEndpoint": "https://testdatacosmosdb.documents.azure.com:443/"
}}

I get the error "Cosmos DB connection configuration 'connect' does not exist. Make sure that it is a defined App Setting. I'm not sure if it happening because of isolated azure functions

DxG
  • 147
  • 4
  • 17

1 Answers1

1

You are missing the credentials. See:

All Azure Functions bindings that are going to use MSI need the <your attribute value>__credential in the configuration besides the Service Specific properties.

For Cosmos DB, the Service Specific property is accountEndpoint.

To summarize, you need to have both.

In your local.settings.json file:

{
   "connect" : {
      "accountEndpoint": "https://testdatacosmosdb.documents.azure.com:443/",
      "credential" : "managedidentity"

    }
}

Once deployed in Azure, you need to add them to your Functions App Configuration, for that you can use the underscore notation:

The version you are using of the package is old and only supports adding these on the "Connection Strings" section of the Function App Configuration.

"connect__accountEndpoint": "https://testdatacosmosdb.documents.azure.com:443/"

"connect__credential": "managedidentity"

Here is also an Azure Friday episode of the whole scenario end to end: https://www.youtube.com/watch?v=w002dYaP9mw

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
  • Adding "credential" property and removing underscore notation didn't help. I watched few videos on using managed identity and everything is for in-process Azure functions. I'm wondering if there is different format for isolated Azure functions. The extension for isolated functions is "Microsoft.Azure.Functions.Worker.Extensions.CosmosDB --version 4.0.0-preview2". But the extension for in-process functions is Microsoft.Azure.WebJobs.Extensions.CosmosDB --version 4.0.0-rc . Both are different extensions. Does this cause any issues ? – DxG Oct 25 '22 at 03:59
  • Are you running locally or deploying the Function on Azure? If deployed, make sure you are putting the underscore notation configs in the **Connection Strings section**. Locally, (local.appsettings.json) I double checked, you don't need the "Values" node (updated answer) – Matias Quaranta Oct 25 '22 at 14:29
  • Regarding the package versions, the Worker packages mirror the other ones, they seem to just be older, but `preview2` contains MSI support. – Matias Quaranta Oct 25 '22 at 14:32
  • It is not working both locally and in portal. But I observed giving the entire connection string like "connect" : "" is working. The prefix option for MSI is not recognized. When you say "double checked" , were you able to make it work with isolated azure functions ? . – DxG Oct 25 '22 at 17:37
  • When running locally you cannot use "credential", because "managedidentity" is not valid. When deployed, you don't deploy your JSON file but instead need to go to the Function App Settings (with underscore notation), are you setting the values in the Connection Strings section? When I say "double checked" is because I checked on the Function examples, the JSON does not have "Values" when setting configs. – Matias Quaranta Oct 25 '22 at 17:45
  • Yes. I set in the connection strings settings. I believe the issue is with reading the prefix itself. For other resources like blobs, queues etc isolated Azure function is able to read the prefix underscore pattern in local.settings.json and in portal as well. It is available in the first link you shared. If there is a working cosmosDB trigger (MSI) example for isolated functions from Microsoft , we could verify if this is a bug or not. – DxG Oct 25 '22 at 18:01
  • Any success in this regard, I have the same issue with Isolated Process, and regarding https://github.com/Azure/azure-webjobs-sdk-extensions/issues/741#issuecomment-1378825621 it might not be supported yet! – Saeed Ganji Jan 11 '23 at 14:32