3

We are using a Cosmos DB input trigger for Azure Functions and are unable to use environment variables in our function.json like other input triggers for sticky slot settings.

Has anyone else had success using environment variables in function.json using Cosmos DB trigger type?

function.json

{
  "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
}

Azure Function Error

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
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • Looks like it is an issue with function runtime. Function is able to read to the connection string from app settings, but collection and database name is not read from function application settings. – Baskar Rao Nov 01 '17 at 02:28
  • Have you also tried it with the `ALL_CAPS`-convention? – Jan_V Nov 01 '17 at 12:01
  • @Jan_V definitely tried variations - underscores, no underscores, hyphens, lower, upper, but seems like the validation for the cosmos lease collection and database is run before the `function.json` is translated using environment variables. – SliverNinja - MSFT Nov 01 '17 at 13:24
  • @Baskar - thanks for [posting this issue in webjobs community!](https://github.com/Azure/azure-webjobs-sdk-script/issues/2086) – SliverNinja - MSFT Nov 01 '17 at 13:32
  • this issue was [moved to webjobs sdk extensions](https://github.com/Azure/azure-webjobs-sdk-extensions/issues/322), hope to see it get updated soon! – SliverNinja - MSFT Nov 07 '17 at 07:25

0 Answers0