Search code examples
azure-functionsazure-app-configuration

How can I read App Configuration Store endpoint and environment from local config store in azure functions?


I am moving our configuration from our local configuration store to a central App Configuration Store for all our Azure Functions.

I have created a startup.cs and the code looks as follows

public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            if (builder == null) throw new ArgumentNullException(nameof(builder));

            builder.ConfigurationBuilder
                .AddEnvironmentVariables();

            var credentials = GetDefaultAzureCredential();

            builder.ConfigurationBuilder
                .AddAzureAppConfiguration((options) =>
                {
                    options
                        .Connect(
                            new Uri(Environment.GetEnvironmentVariable("ConfigurationStorePrimaryEndpoint")),
                            credentials
                        )
                        .Select(KeyFilter.Any, LabelFilter.Null)
                        .Select(KeyFilter.Any, "DEVELOPMENT");
                });

        }

I cannot figure out how to read the variables ConfigurationStorePrimaryEndpoint and DEVELOPMENT from the local Configuration on the function itself? I do not want to use env variables I want to read those two values from the local configuration store on each function but I cannot figure out how?

And of course when run locally I want it to use the local.settings.json

Any suggestions appreciated.


Solution

  • Environment.GetEnvironmentVariable("SomeConfigurationSetting") would load value of "SomeConfigurationSetting" key from local.settings.json when you run locally. When you deploy in Azure, just add the same entry in app settings of the Function app. It does not have to be "Environment variable" literally like in OS level. Refer this for details.

    If you don't want this way and you meant some custom "local configuration store", then you need to share details on that.