Reputation: 85
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!
Upvotes: 0
Views: 1267
Reputation: 3473
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.
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
cron expression
Result :
Upvotes: 0
Reputation: 1197
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)"
}
This thing is still in preview so I wont recommend it to use in production.
Upvotes: 0