Thomas M. H.
Thomas M. H.

Reputation: 55

How to use Elastic Beanstalk environment properties in ASP MVC

I am trying to set up a multi environment Elastic Beanstalk ASP MVC solution.

Environment specific settings, such as connection strings and remote endpoints are stored in web.config.

This article leads me to believe that it should be possible to define properties on the Configuration "Modify software" -> "Environment properties" section of my Elastic Beanstalk environment configuration. The article is linked from that page.

To test this, I created an Elastic Beanstalk application with a single environment. On the Configuration -> "Modify software" page I defined one property KEY1 with the value custom1

I then set up a new ASP MVC 5 .NET 4.6.1 web solution in Visual Studio 2017, with a single controller/action which simply loops through ConfigurationManager.AppSettings and Environment.GetEnvironmentVariables( ) and renders them on the page.

In web.config I have

<appSettings>
    <add key="KEY1" value="default1"/>
    <add key="KEY2" value="default2"/>
    ...
</appSettings>

When I view the page on my elasticbeanstalk.com URL, I don't see the value from my environment properties! Instead I see:

KEY1 = default1
KEY2 = default2

Where I would have expected

KEY1 = custom1
KEY2 = default2

And in the output of Environment.GetEnvironmentVariables( ) I don't see KEY1 or KEY2

The documentation explicitly says that

Elastic Beanstalk doesn't support passing environment variables to .NET Core applications and multiple-application IIS deployments that use a deployment manifest

But this is a classic ASP MVC 5 application.

What am I missing?

Upvotes: 0

Views: 751

Answers (1)

Thomas M. H.
Thomas M. H.

Reputation: 55

Found the answer in this Stack Overflow post.

What I was missing was the fact that the param will only be added if it does not already exists in the <appsettings> part of web.config.

This was a surprise, coming from Octopus Deploy where the keys has to exists in <appSettings>.

Upvotes: 1

Related Questions