How to read Beanstalk resilient media properties in .net?

How can I read environment properties from my AWS Elastic Beanstalk application, which can be found here:

Configuration > Software Configuration > Environment Properties 

enter image description here

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") 

A "fully qualified" name attempt comes from AWS EB documentation .

Any ideas?

+9
amazon-web-services elastic-beanstalk
Nov 01 '15 at 14:21
source share
2 answers

In your .ebextensions/myoptions.config :

 option_settings: - option_name: MyServiceUrl value: change me 

This will add the "MyServiceUrl" parameter to the "EB Environment Properties" section (as you can already see). When deployed, this will add the following to your Web.Config file:

 <appSettings> <add key="MyServiceUrl" value="change me" /> </appSettings> 

If you use RDP in your EC2 instance, you will see this.

When you change a property using the EB console, this setting will be changed in your Web.Config file.

So, you get access to this property using the standard AppSettings method:

 string value = ConfigurationManager.AppSettings["MyServiceUrl"]; 

Catch:

You need to make sure that your Web.Config file Web.Config not contain this parameter, otherwise EB will not replace it. If your Visual Studio deployment package includes this option, EB will not replace it, and you will always get the expanded value when accessing the property through your code.

Decision:

In the Web.Release.config file Web.Release.config remove the parameter during the deployment of Visual Studio:

 <appSettings> <add key="MyServiceUrl" xdt:Transform="Remove" xdt:Locator="Match(key)" /> </appSettings> 

This will remove the parameter from Web.Config during the deployment of Visual Studio and allow EB to add the value to the file during the deployment of EB.

+14
Nov 01 '15 at 18:39
source share

Looks like this behavior has changed in Elastic Beanstalk. Docs now say

Settings used in the AWS Management Console override settings in the configuration files, if they exist. This allows the default settings in the configuration files and override them using environment-specific settings in the console.

So now you can use the same configuration names in your web.config and in the Elastic Beanstalk configuration, and Elastic Beanstalk values โ€‹โ€‹will override any in your web.config. It seems that EB is just adding new entries to the web.config file, so there will be two entries for any values โ€‹โ€‹defined in both places. Since entries added to EB are later in the file, they take precedence.

0
Nov 08 '17 at 15:43 on
source share



All Articles