.NET 5 Azure Function (dotnet-isolated) - Input binding from keyvault

Prabhakaran, Prabhu 1 Reputation point
2021-04-23T11:12:12.343+00:00

I am trying to connect my function app to keyvault and get queue name and connection secrets. This was working well with .netcore3.1 app using the ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder) method in FunctionStartup.

After upgrading to .net5 dotnet-isolated, the bindings does not work. I configured azurekeyvault in Program.cs but still it does not pick from keyvault. Seems like functionstartup is trying to bind before Main() is invoked.

QueueFunction

 public static void Run([QueueTrigger("%QueueName%", Connection = "QueueConnection")] string message, string id)

Startup.cs (.netcore3.1)- working

 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        var azureKeyVaultURL = Environment.GetEnvironmentVariable("AzureKeyVaultURL");
        var azureKeyVaultADAppID = Environment.GetEnvironmentVariable("AzureKeyVaultMIAppID");


        builder.ConfigurationBuilder
                    .SetBasePath(Environment.CurrentDirectory)
                    .AddAzureKeyVault(new Uri(azureKeyVaultURL), new ManagedIdentityCredential(azureKeyVaultADAppID))
                    .AddEnvironmentVariables()
                .Build();
    }

Program.cs (.net5)- Not working

var host = new HostBuilder()
            .ConfigureFunctionsWorkerDefaults()
            .ConfigureAppConfiguration(config =>{
                 var azureKeyVaultURL = Environment.GetEnvironmentVariable("AzureKeyVaultURL");
                var azureKeyVaultADAppID = Environment.GetEnvironmentVariable("AzureKeyVaultMIAppID");

                config
                   .SetBasePath(Environment.CurrentDirectory)
                   .AddAzureKeyVault(new Uri(azureKeyVaultURL), new ManagedIdentityCredential(azureKeyVaultADAppID))
                   .AddEnvironmentVariables()
                .Build();
            })
.Build()
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,118 questions
Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
109 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,020 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.