skip to Main Content

I am currently reading the Schedule parameter for my Azure Function Timer Trigger from local.settings.json. However, I would like to read it from Azure App Configuration instead. The problem is that since the configuration is connected after the project has started, I am unable to read it from there. Can anyone suggest a solution?

In my Azure Functions project, I have already set up Azure App Configuration and have the necessary connection details. I want to retrieve the Schedule parameter dynamically from Azure App Configuration so that any changes to the Schedule in the configuration are reflected without restarting the Azure Function.

By the way, I don’t have any issues reading a key from IConfiguration within any function.

Any help or suggestions would be greatly appreciated. Thank you!

enter image description here

enter image description here
enter image description here

2

Answers


  1. The issue is azure function needs this before starting execution, when you use the %SOMETHING% then it tries to read it from the azure function app configurations (local.setting.json, Environment or azure function configuration on azure portal).

    if it finds these values then it will run the host builder things.

    What to do?
    For local development you can use the local.settings.json and when you are deploying it on azure you can use something called configuration referencing.

    OR you can also use this locally, try to add this in local.settings.json

    @Microsoft.AppConfiguration(Endpoint=https://myAppConfigStore.azconfig.io; Key=myAppConfigKey)​
    

    example

    {
      "CronExpression":"@Microsoft.AppConfiguration(Endpoint=https://myAppConfigStore.azconfig.io; Key=myAppConfigKey)​"
    }
    

    Make sure, while for local you have the access and for deployed version application has access to the azure app configuration.

    This thing is still in preview so I wont recommend it to use in production.

    Login or Signup to reply.
  2. Thank you @Manish

    • I have created app configuration in portal to connect with my timer trigger function.

    • I have tried to connect as you done in the above method but, Iam unable to work.

    I have got the same errors that which you got.
    enter image description here

    • Then, I modified the code by creating a class Startup.cs in the project and setup "AzureAppConfigurationConnectionString" in local.settings.json

    Startup.cs :

    namespace FunctionApp5
    {
        public class Startup : FunctionsStartup
        {
            public override void Configure(IFunctionsHostBuilder builder)
            {
                // Configure services if needed
            }
    
            public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
            {
                IConfigurationRoot configuration = builder.ConfigurationBuilder.Build();
    
                builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
                {
                    options.Connect(configuration["AzureAppConfigurationConnectionString"])
                        .ConfigureRefresh(refreshOptions =>
                        {
                            refreshOptions.Register(key: "TimerSchedule", refreshAll: true);
                        })
                        .UseFeatureFlags();
                });
            }
        }
    }
    

    FunctionApp5 :

    namespace FunctionApp5
    {
        public class Function1
        {
            private static IConfiguration _configuration;
            public Function1(IConfiguration configuration)
            {
                _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            }
    
            [FunctionName("Function1")]
            public static void Run([TimerTrigger("%TimerSchedule%")] TimerInfo timerInfo)
            {
     
            }
        }
    }
    

    local.settings.json

    enter image description here

    • Then, I created a key-value in my app configuration for cron expression

    enter image description here

    Result :
    enter image description here

    • I am able see the function triggering at per schedule time parameter from Azure App Configuration.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search