For the past few years I’ve been developing and deploying web applications using Amazon Web Services (AWS). Most recently, I’ve been working on a project called Initial Commit, the goal of which is to build a website and set of eBooks that help curious developers learn how their favorite programs are coded.

In the process, I discovered a very convenient way to deploy and host web applications on AWS using the Elastic Beanstalk service (EBS). And, today I will share how to deploy .NET web applications with AWS Elastic Beanstalk.

There are two main reasons that I recommend using AWS EBS to deploy and host your web application: convenience and cost.

The convenience factor comes from the fact that once you have a built version of your application code, you can simply following the simple set of EBS configuration steps, which include uploading a ZIP file containing your application code.

After the upload and configuration are done, EBS will provide you a one-click deployment that will take care of spinning up a web server to host your application, and will do the dirty work of configuring it and deploying your web app.

Although in certain cases you may run into a few sticky configuration bugs that may require some Googling to figure out, the work required will be much less that it would take to manually set up a web server, configure it, and deploy your web app. Once you have the working through EBS, re-deploying a new version of your code is a one-click job.

The cost factor comes from the fact that AWS pricing is very reasonable for what you get. You will likely pay a little more than you would for bare bones hosting on another site, but in my opinion the reliability and convenience of AWS makes it well worth the slight investment. If you plan on starting with a relatively small application, you can opt for the T2-micro offering, which will qualify for AWS’ “free tier” for one year. This means that the first year of hosting could be free unless you opt for a larger hosting instance. In my experience, running a site based on a T2-micro instance after the free tier expires costs approximately $30 per month.

Packaging the .NET Application Code for AWS EBS

Before we walk through the steps to deploy the web app using AWS EBS, let’s discuss a few points for packaging the application code in a way that EBS will be able to digest it.

The application code will reside in the project root directory; let’s refer to it as `website1` in this example. So the ` website1` directory will contain the compiled application code, which will mostly comprise of a set of DLL files along with some other configuration files, such as JSON, PDB, and other configuration files.

The ` website1` directory needs to compressed into a ZIP file, while making sure to leave out any OS specific files or folders that may cause issues, such as the `__MACOSX` and `.DS_STORE` in OSX. This can be done in a DOS prompt or terminal window – after navigating into the ` website1` folder – using the following command:

`zip -r website1.zip . -x “.*” -x “__MACOSX”`

Now, that we have compressed our application code in a clean format, we need to create an EBS configuration file called `aws-windows-deployment-manifest.json`. The default contents for this file as provided in the AWS documentation are provided here:

{

“manifestVersion”: 1,

“deployments”: {

“aspNetCoreWeb”: [

{

“name”: “webapp1”,

“parameters”: {

“appBundle”: “website1.zip”,

“iisPath”: “/”,

“iisWebSite”: “Default Web Site”

}

}

]

}

}

As you can see, this file contains some basic metadata information related to the deployment, such as the name of the `appBundle` being deployed, and the deployment path. If this file is not present the deployment will fail.

Now, the final packaging step involves placing the application bundle ZIP file – in our case `webapp1.zip` – and the `aws-windows-deployment-manifest.json` file into the same directory. Now we must compress these two files into one file ZIP file, which we can do using the following command:

`zip -r webapp1.zip . -x “.*” -x “__MACOSX”`

This will produce our final package `webapp1.zip` which will be ready for deployment to AWS EBS.

Also Read: How to create user signup form in ASP.NET using C# and MySQL.

Let’s now see the steps to deploy our .NET web application to AWS Elastic Beanstalk.

Deploying the Packaged .NET Application to AWS EBS

Step 1: Browse to https://aws.amazon.com, create an AWS account, and sign into the AWS console with that account.

Step 2: Set up your billing information since AWS will start charging to use their services at some point in the future. (Note: we won’t go into more detail on steps 1) and 2) since they are fairly self-explanatory).

Step 3: Once you are logged into the AWS console, click the `Services` link in the upper left corner the page.

Step 4: In the `Compute` section, click on the link for `Elastic Beanstalk` or search for it in the search box.

Step 5: Click on the `Create New Application` link in the upper right corner of the page.

Step 6: Enter a name and description for the application and click the `Create` button.

Step 7: Click on the `Create one now.` link to create a new environment in the new application.

Step 8: Choose `Web server environment` and click the `Select` button

Step 9: Scroll down to the `Basic configuration` section, and choose `.NET (Windows/IIS)` from the `Preconfigured platform` dropdown menu.

Step 10: Scroll down and choose the `Upload your code` radio button in the `Application code` section.

Step 11: Click the `Choose file` button, browse to and select the source bundle ZIP file `webapp1.zip` created above, and click the `Upload` button.

Step 12: Click the `Create environment` button.

At this point, AWS will take a few minutes to spin up your environment. Once complete, it will provide a URL, which you can use to access your application in an Internet browser. Note that depending on your specific setup, there is a chance you may need to tweak some of the security and/or configuration settings in the Elastic Beanstalk environment, or in your app code itself before your application will work properly.

Now that your application is up and running, you’ll notice that Elastic Beanstalk has some additional features that make monitoring, updating, and troubleshooting a breeze. High level monitoring is achieved by a Health check on the environment page which appears as a large green checkmark when healthy.

When issues are detected, this icon will turn red and the causes will be identified. To the right is the `Upload and Deploy` button, which will allow you to easily upload a new version of your packaged code and redeploy it at the click of a button.

Scrolling down on the environment page shows a table of recent application events, and detailed logs can be accessed on the left sidebar for more in-depth troubleshooting.