Home > Software design >  appsettings.json read properly when deployed as Azure Function App Container, but not when deployed
appsettings.json read properly when deployed as Azure Function App Container, but not when deployed

Time:04-10

I have a Function App which is successfully running locally and successfully running as "Azure Function App Container", but when I'm trying to deploy it as simply "Azure Function App", right after publishing it can't read the fields that I put in the appsettings.json file (I put there s3 key access and secret key among other things), the error that is shown is that "No RegionEndpoint or ServiceURL configured", which should be taken from the appsettings.json file. This is what happens in my startup class:

public override void Configure(IFunctionsHostBuilder builder)
    {
        var config = new ConfigurationBuilder()
           .SetBasePath(Environment.CurrentDirectory)
           .AddJsonFile("appsettings.json", false)
           .AddUserSecrets(Assembly.GetExecutingAssembly(), false)
           .AddEnvironmentVariables()
           .Build();

        builder.Services.AddLogging();
        builder.Services.AddSingleton<IConfiguration>(config);
        builder.Services.AddSingleton(svc =>
           {
               var client = new AzureLogAnalyticsClient(
                 config[LogAnalyticsWorkspaceID],
                 config[LogAnalyticsKey]);
               client.TimeStampField = config["LogAnalyticsTimestampField"];
               return client;
           });
    }

CodePudding user response:

An Azure Function App deployment will not read appsettings.json by default. Instead, put those configuration values in the Azure Function's application settings.

This can be done by logging into the Azure portal, going to your Azure Function, then:

  1. Click "Configuration" on the Azure Function blade.
  2. Choose Application Settings in the header.
  3. Enter your settings in the table below.
  • Related