How can I read the Environment Properties from my AWS Elastic Beanstalk Application found here:
Configuration > Software Configuration > Environment Properties
None of the following approaches work:
ConfigurationManager.AppSettings["MyServiceUrl"]
ConfigurationManager.AppSettings["aws:elasticbeanstalk:application:environment.MyServiceUrl"]
Environment.GetEnvironmentVariable("MyServiceUrl")
Environment.GetEnvironmentVariable("aws:elasticbeanstalk:application:environment.MyServiceUrl")
The 'fully qualified' name attempt comes from the AWS EB documentation.
Any ideas?
It looks like this behavior has changed in Elastic Beanstalk. The docs now say
So you can now use the same config names in your web.config and in the Elastic Beanstalk config, and the Elastic Beanstalk values will override any in your web.config. It looks like EB simply adds new entries to the web.config file, so there will be two entries for any values defined in both places. Since the EB-added entries are later in the file they take precedence.
In your
.ebextensions/myoptions.config
file:This will add the "MyServiceUrl" option in your EB Environment Properties section (as you're seeing already). When deployed, this will add the following to your
Web.Config
file:If you RDP into your EC2 instance, you'll see this.
When you change the property using the EB console, the setting will be modified in your
Web.Config
file.So you access this property using the standard
AppSettings
method:The Catch:
You need to ensure that your
Web.Config
file does not contain this setting, otherwise EB does not replace it. If your Visual Studio deployment package includes this setting, then EB will not replace it and you will always receive the deployed value when you access the property via your code.The Solution:
In you
Web.Release.config
file, have the setting removed during Visual Studio deployment:This will remove the setting from
Web.Config
during Visual Studio deployment and will allow EB to add the value into the file during EB deployment.It is true that on AWS Doc (Using the AWS Elastic Beanstalk .NET Platform) it is indicated :
... I think it refers to the .ebextensions configuration files, and not the app.config or web.config files. See in link indicated above, there is reference to the 'precedence' rules that apply ; it is indicated that what takes precendence are 'Settings specified during a create environment or update environment', so what I understand is settings values set during the deployement take precedence (and these settings are in the app.config/web.config).
I have just tested this, and Matt Houser answer above is correct and still stands. You have to remove app.config/web.config keys on in the deployed version to see the 'Environment properties' be taken into consideration.