question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Function app settings not read when a function is developed in portal using Cosmos DB Trigger

See original GitHub issue

From @baskar3078 on November 1, 2017 2:49

When we develop a function using Cosmos DB Trigger in azure portal, the database and collection names are not read from function application settings in function.json file.

Investigative information

https://stackoverflow.com/questions/47043182/azure-functions-function-json-cosmos-trigger

Repro steps

  1. Create a function using CosmosDB Trigger portal
  2. Add an function application setting with Key - “cosmos-triggers-database-name” and any value
  3. Update the function.json as below
{
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "inputDocs",
      "direction": "in",
      "leaseDatabaseName": "leases",
      "leaseCollectionName": "MyCosmosCollection-myFunction",
      "connectionStringSetting": "CosmosTriggers-SourceAdapter",
      "databaseName": "%cosmos-triggers-database-name%",
      "collectionName": "MyCosmosCollection",
      "createLeaseCollectionIfNotExists": true
    }
  ],
  "disabled": false
}
  1. Save and run the function

Expected behavior

Expected behavior is to read the document from Cosmos DB.

Actual behavior

Function ($myFunction) Error: The listener for function 'Functions.myFunction' was unable to start.
 Microsoft.Azure.WebJobs.Extensions.DocumentDB: Either the source collection 'MyCosmosCollection' (in database '%cosmos-triggers-database-name%') or the lease collection 'MyCosmosCollection-myFunction' (in database 'leases') does not exist. Both collections must exist before the listener starts. To automatically create the lease collection, set 'CreateLeaseCollectionIfNotExists' to 'true'. Microsoft.Azure.Documents.Client: Message: {"Errors":["Resource Not Found"]}
 ActivityId: b00f7802-fccb-47eb-972d-0bd70ec896c1, Request URI: rntbd://bn6prdddc05-docdb-1.documents.azure.com:14639/apps/6628b461-75d4-4e4a-9897-ada4076dc30c/services/1b0fc27a-de15-45cf-a1b2-ebfce044d1e2/partitions/34cfee55-54aa-4e31-81f4-08cf1bfdf62f/replicas/131523094168492638s/.
 Session Id: 092ccb7ce9104407bf56c26a5cc8b119
 Timestamp: 2017-10-31T19:13:03.914Z

Known workarounds

We need to explicitly mention the database and collection name in function.json file.

Related information

https://stackoverflow.com/questions/47043182/azure-functions-function-json-cosmos-trigger

Copied from original issue: Azure/azure-webjobs-sdk-script#2086

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
brettsamcommented, Feb 16, 2018

I was confused as well. I took a look and have submitted #370 which should fix it.

There were 2 things:

  • The NameResolver keys won’t contain %%. They basically just do a straight lookup. That’s why the tests passed.
  • You need to use the ResolveWholeString extension in order to evaluate with the %%.
0reactions
ealsurcommented, Feb 16, 2018

Is the AutoResolve logic defined somewhere @brettsam ? Ideally we would like to mimic it (since it doesn’t work for Triggers) but it seems to be more than just using the NameResolver.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot issues with the Azure Functions trigger for ...
This article discusses common issues, workarounds, and diagnostic steps when you're using the Azure Functions trigger for Azure Cosmos DB.
Read more >
Cosmos DB trigger is not able to read appsettings using ...
We have implemented COSMOS DB trigger using azure functionv3 . It is not always reading the appsettings. some time it works some times...
Read more >
Handle events with Azure Functions and Azure Cosmos DB ...
... Functions bindings to integrate a function with Azure Cosmos DB SQL API. ... Create an Azure Function using the Azure Cosmos DB...
Read more >
Build API using Azure Function with Python and ... - Evan Wong
In this tutorial, we're going to build a Serverless API using HTTP Triggers in Azure Functions that uses a Azure Cosmos DB as...
Read more >
How to trigger an Azure Function from Azure Cosmos DB
Navigate to the Function App in the Azure portal · Click on the Functions menu · Select Create. This opens the Create function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found