Displaying AppVersion for an ASP.Net Elastic Beanstalk Web Application

ASP.NET developers are most familiar with using configuration that is driven from the Web.config by adding a key-value pair to the appSettings section.  In AWS, Elastic Beanstalk Configuration allows a developer to create key-value pairs in the same way, but this configuration is driven directly from the Elastic Beanstalk configuration and interface.

 

AWS will substitute a configuration key that is set up in the Elastic Beanstalk console ONLY if it is NOT present in the deployed Web.config.  So, in order to use the Elastic Beanstalk configuration, it is necessary to delete the existing appSetting keys prior to deployment. This requires the use of a Config Transform which can be set up by right-clicking the Web.config and selecting Add Config Transform.  The Config Transform file (which is really just a specialized XSLT) will be named based on the build configuration name, in most cases (Debug or Release, for example), the Debug configuration will use Web.Debug.config.  

Once a Config Transform is added, open the Config Transform for each specific configuration, and add the following to the <appSettings/> section:

<add key="AppVersion" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
<add key="BuildNum" xdt:Transform="Remove" xdt:Locator="Match(key)"/>

 

This instructs Visual Studio to remove the AppVersion and BuildNum keys from the deployed Web.config.  Without these keys present in the Web.config, during the deployment, AWS will locate these keys from within Elastic Beanstalk and substitute them in the deployed Web.config.  Developers can continue to keep these in the regular Web.config for local development.  This approach can be extended to include database connection strings, custom error configuration and anything else which is configuration from within the Web.config.

 

Displaying the Application Version in the Web App

To display the Elastic Beanstalk driven configuration, developers use the same ConfigurationManager syntax to access and use any standard appSetting.  The following is a snippet that can be added to the footer of your Web Application:

 

©2017 MyApp.com <span class="small-text"> v.@ConfigurationManager. AppSettings["AppVersion"] (Build @ConfigurationManager.AppSettings["BuildNum"])</span>

 

Deployment to an Existing Elastic Beanstalk Environment

New application versions can be deployed to Elastic Beanstalk directly from within Visual Studio.  The instructions below assume you have installed the AWS Toolkit for Visual Studio (https://aws.amazon.com/visualstudio/) and configured with an AWS account profile that has access to deploy to AWS.

 

Web

  1. Open the Visual Studio Solution (e.g. MyApp-Web.sln)
  2. Right click the Web project and select Publish to AWS… (Figure 1)

    Figure 1 – Right Click Publish

     

  3. From the dialog, click Redeploy to an existing environment and select an environment (Figure 2).

    Figure 2 – Redeploy to an existing environment

     

  4. Under Application Settings, the AWS Toolkit will generate a default Deployment Version Label which is based on the current date.  You will want to inject a standard versioning scheme between the “v” and the unique deployment version.  For example, if you are deploying version 2.1.0, then change v20160126125432 to v.2.1.0-20160126125432.  (Figure 3)

    Figure 3 – Default deployment Version Label

     

  5. For first time deployments with the new version and build configuration, add an AppVersion and a BuildNum key.  (Figure 4)

    Figure 4 – AppVersion and BuildNum configuration keys

     

  6. Set AppVersion to the version you are deploying, in our example this would be set to 2.1..0.
  7. Set BuildNum to generated AWS deployment version without the “v”, in our example above this would be set to 2016012612441.
  8. Confirm settings and Deploy (Figure 5)

    Figure 5 – Deploy

 

Deploying an Application Version to a Subsequent Environment in the Release Cycle

Once a new version is ready to be released into an environment later in the cycle (e.g. TEST or PROD), you must use Elastic Beanstalk to deploy that Application Version to the new environment.  There is a manual step to update the AppVersion and BuildNum once the new Application Version is deployed.  This can be automated in the future.  Both steps are covered below.

 

Deploy

Deploy an Application Version using the AWS Elastic Beanstalk console as follows:

 

  1. Log in to the AWS console with an account that has permission to access and deploy from within Elastic Beanstalk.
  2. Go to the Elastic Beanstalk Service and select MyApp | Application Versions.
  3. Select the checkbox next to the version you would like to deploy.  The version label will match the Deployment version label that you set during the Visual Studio deployment.
  4. Click the Deploy button.
  5. From the dropdown, select the environment where you want to deploy this version.

 

Update the Configuration Variables

Once the new version is deployed, manually update the version and build number within the Elastic Beanstalk console as follows:

 

  1. Log in to AWS
  2. Select the environment where you just deployed the release
  3. Select Configuration
  4. Under Environment Properties, update the AppVersion and BuildNum values to match the deployed version.  For example, if the deployment label is v.2.1.0-2016012612441, then set AppVersion to 2.1.0 and BuildNum to 2016012612441
  5. Click Apply.  The environment will run through a brief update and will then be available.

While there are some manual steps with this approach (we will address automated build approaches in another blog post), this allows Application version and build # to be synchronized and coordinated between the Development environment and the deployed Elastic Beanstalk environments.

 

Clay Benoit

Clay Benoit has over 18 years of experience as a software developer, building applications for companies, organizations and federal agencies. He has a passion for delivering quality, usable software that helps our customers solve a problem. In addition to his strong technical and leadership skills, he is well respected by our customers and his colleagues for his dedication and professionalism. His latest technology focus is implementing applications using ASP.NET Core, Angular 2 and Web API and other exciting and emerging frameworks like TypeScript, MaterializeCSS and AWS Lambda. Outside of technology, he is a competitive cyclist, health and fitness geek, avid boater and a devoted owner of three Boxers.

No Comments

Post a Comment

Comment
Name
Email
Website