Created
June 5, 2018 12:31
-
-
Save icardosos/e2bd2805b21f25c94794e427a6319821 to your computer and use it in GitHub Desktop.
Enable hosting environment to asp.net on AWS Elastic Beanstalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class HostingEnvironmentExtensions | |
{ | |
public static void ConfigureAWSEnvironment(this IHostingEnvironment env) | |
{ | |
var awsEnvVariablePath = "C:\\Program Files\\Amazon\\ElasticBeanstalk\\config"; | |
var awsEnvVariableFile = "containerconfiguration"; | |
if (!File.Exists(awsEnvVariablePath + "\\" + awsEnvVariableFile)) | |
return; //não executar em dev | |
var builder = new ConfigurationBuilder() | |
.SetBasePath(awsEnvVariablePath) | |
.AddJsonFile(awsEnvVariableFile, optional: true, reloadOnChange: true); | |
var configuration = builder.Build(); | |
var envVariables = configuration.GetSection("iis:env").GetChildren(); | |
var envKey = envVariables.FirstOrDefault(v => v.Value.StartsWith("ASPNETCORE_ENVIRONMENT=")); | |
if (envKey != null) | |
env.EnvironmentName = envKey.Value.Split('=')[1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment