I have an Azure Function App (>=4.0 version), that has an Azure Cosmos function.
I am retrieving the value for the CreateLeaseContainerIfNotExists parameter from the environment. In Program.cs I am retrieving it into builder.Services().Bind() function.
The AppConfigClass is:
public class AppConfigValues
{
public const string AppName = "BoundedContextSolution.Aggregate1NameSpace.IntegrationEventPublisher";
public bool? CreateLeaseContainerIfNotExists { get; set; } = false;
}
In the Function itself, I want to retrieve the value for CreateLeaseContainerIfNotExists from the environment variable of with the name of AppConfigValues.AppName plus
CreateLeaseContainerIfNotExists which would be "BoundedContextSolution.Aggregate1NameSpace.IntegrationEventPublisher.CreateLeaseContainerIfNotExists".
public static void Run([CosmosDBTrigger(
databaseName: "databaseName",
containerName: "containerName",
Connection = "",
LeaseContainerName = "leases",
CreateLeaseContainerIfNotExists = true)] IReadOnlyList<ToDoItem> input,
ILogger log]
2
Answers
This worked:
CosmosDB
trigger does not allow runtime values for properties likeCreateLeaseContainerIfNotExists
,databaseName
,containerName
,LeaseContainerName
,Connection
, as these attributes parameter is set during compile time.we can define the values for
databaseName
,containerName
,LeaseContainerName
, in environment variable. using"%<variable_name>%"
andConnection
already fetches value from environment variable.But
CreateLeaseContainerIfNotExists
requires Boolean value which cannot be defined using string value.By default
CreateLeaseContainerIfNotExists
is set tofalse
.If it is set to
true
, it will create the lease container if no container is available with name defined inLeaseContainerName
. But if Container already exists then it skips this step and uses pre-existing container.OUTPUT
:Test
container is created