Search code examples
c#azureazure-functionsazure-cosmosdbazure-app-configuration

Why does Azure functions (isolated worker) fail indexing? CosmosDbTrigger binding using Azure App Configuration fails with does not resolve to a value


I am trying to source configuration from Azure App Configuration and use the values in my CosmosDbTrigger parameters. I am using the isolated worker, migrating from in-process. This used to work but now that I am using the isolated worker, the function fails indexing. It does not seem to see the values from App Configuration.

Any guidance or help you can provide would be greatly appreciated.

App Configuration added as a provider in using .ConfigureAppConfiguration

    var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureAppConfiguration(configBuilder =>
    {
        //connection variable omitted for brevity and security
        configBuilder.AddAzureAppConfiguration(connection);
    })

The in-process code used something like this but was in a Startup.cs file in the

    public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        var config = builder.ConfigurationBuilder
            .AddEnvironmentVariables()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true);
        config.AddAzureAppConfiguration(connection);
        _config = config.Build();
    }

Sample function

[Function(nameof(SampleFunction))]
public async Task SampleFunctionAsync([CosmosDBTrigger(
    databaseName: $"%{Constants.CosmosDatabaseEnvName}%",
    containerName: $"%{Constants.SampleContainerNameEnvName}%",
    Connection = $"{Constants.CosmosConnectionEnvName}",
    LeaseContainerName = "leases",
    CreateLeaseContainerIfNotExists = true)] IReadOnlyList<JObject> documents
  )

...

Expected Results

I am expecting that the string values in the static constants class will resolve to the key/value pair in Azure App Configuration. So, for example,

public static class Constants
{
    public const string CosmosDatabaseEnvName = "my_cosmos_database"
}

Then in Azure App Configuration

my_cosmos_database is configured with the-actual-database-name as the value

the-acutal-database-name should be used as the parameter value for databaseName and so on.

Actual Results

Function failed indexing <parameter> does not resolve to a value

Azure Functions Worker Runtime: dotnet8-isolated Azure Functions Version: 2.0

Applicable Nuget packages

<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="7.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="4.5.0" />

I have also verified that if I use app settings, the configuration is read in correctly. It just doesn't work from Azure App Configuration.


Solution

  • As per December 2023, it looks like this is not supported:

    How to use Azure App Config Service with Azure Functions for binding input parameters:

    worker configuration sources are not currently supported by extensions/bindings, as that configuration must be available at the app/platform level (platform components depend on that configuration).

    As mentioned in the issue, there is preview feature to work with app config same as key vault reference: