SunilS
SunilS

Reputation: 2278

Azure Function cosmosdb Environment settings

Hi I am writing Azure function trigger to capture changes for cosmosdb. I am facing a basic problem.

In function.json, I would like to keep the below parameters dynamic ( It should be picked from environment variable). The reason is that the same app will be deployed in multiple environments and they may have different database name.

      "databaseName": "CosmosDbName",
      "collectionName": "UserCollectionName",

I tried setting the values in local.settings.json to test it but it failed and didn't pick the values.

Any suggestions ?

Found the solution

      "databaseName": "%CosmosDbName%",
      "collectionName": "%UserCollectionName%",

Upvotes: 2

Views: 1052

Answers (1)

suziki
suziki

Reputation: 14080

Yes, as you finally found, for the string type, you can use the method %% to set dynamic parameters, and then set the corresponding value in the environment variable(locally, it is set in local.settings.json. On Azure, it needs to set in the Configuration.), %% will match the corresponding value. It should be noted that the dynamic setting of %% is only applicable to string type, other types are not.

Set it like this in the function definition section:

  "databaseName": "%CosmosDbName%",
  "collectionName": "%UserCollectionName%",

Then fill in the corresponding key values in the settings.

Upvotes: 5

Related Questions