2

In my .net core 1.1 app I have different configurations, which are written in appsettings.json files: appsettings.dev.json, appsettings.production.json, appsettings.test.json.

For each configuration I have different environments in AWS Beanstalk. Right now I'm deploying to Beanstalk by uploading zip file, which contains compiled .net core code and AWS manifest. By default .net core is using production configuration. I was trying to override it several ways:

  • dotnet publish --configuration Test
  • added environment variable ASPNETCORE_ENVIRONMENT Test in Beanstalk software configuration
  • added web.config in which specify ASPNETCORE_ENVIRONMENT environment variable

It doesn't work. The only way which I found work for me was .UseEnvironment("Test"):

    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseSetting("detailedErrors", "true")
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            // TODO: fix me! It's used for AWS deployment
            .UseEnvironment("Test")
            .Build();

        host.Run();
    }

It means that before deployment I need to change hardcoded configuration and it isn't a nice solution.

Does anyone knows how to deal with different configurations in AWS Beanstalk?

Algirdas
  • 1,065
  • 1
  • 9
  • 21
  • Looks like a bug in .Net Core hosting in Elastic Beanstalk. See this answer to a very similar question for a potential workaround: http://stackoverflow.com/a/43221055/808532 – Ryan Weir May 11 '17 at 09:30
  • Seems this has been resolved as of June 29 2020: https://stackoverflow.com/a/62663293/551113 – user551113 Oct 14 '20 at 13:26

0 Answers0