How do I get environment variables from elastic beanstalk into an asp.net core mvc application? I have added a .ebextensions folder with app.config file in it with the follo
.NET Core 2 + posrgresql RDS
Further to @sebastian's great answer above, I found that the settings were in a different part of the file, viz. plugins:rds:env.
Also there was no need to split on =, so the parsing code I have is:
private static void SetEbConfig()
{
var tempConfigBuilder = new ConfigurationBuilder();
tempConfigBuilder.AddJsonFile(
@"C:\Program Files\Amazon\ElasticBeanstalk\config\containerconfiguration",
optional: true,
reloadOnChange: true
);
var configuration = tempConfigBuilder.Build();
var ebEnv = configuration.GetSection("plugins:rds:env")
.GetChildren()
.ToDictionary(child => child.Key, child => child.Value);
foreach (var keyVal in ebEnv)
{
Environment.SetEnvironmentVariable(keyVal.Key, keyVal.Value);
}
}
The relevant (and redacted ;-)) JSON is as follows:
{
"plugins": {
"rds": {
"Description": "RDS Environment variables",
"env": {
"RDS_PORT": "....",
"RDS_HOSTNAME": "....",
"RDS_USERNAME": "....",
"RDS_DB_NAME": "....",
"RDS_PASSWORD": "...."
}
}
}
}
(This reply is separate since I don't have rep to comment...)