Hosting ASP.NET + SQL Server Web application on AWS

In this article I will try to summarise on the steps to host a Microsoft Stack Web Application using ASP.net and SQL Server on AWS cloud. To start with we will assume that you already have a functional asp.net web application that uses SQL server as backend db.

Let’s start by logging onto our AWS account, if you don’t have one you can create it for free at https://aws.amazon.com.

1. Create RDS database

We will create a database on AWS first. On your home page select “Services” from the top menu and then click on “RDS” under Databases category.

Select database engine as “Microsoft SQL Server” and then select an appropriate edition as per your license requirement. For our example I have selected Express Edition.

Once you are done, in the next page you need to select a suitable license model, db version etc. Then at the last section you need to set db name, username and password for your new database. In my case I have created a database named “XXXX” with username “XXXX”. Note that your db name should be unique for all db instances owned by you in the current region.

In the next page you can configure any advanced settings. For our example, I will leave default. And don’t forget to note down the details that are displayed to you once you create your database.

2. Login to newly created RDS database

Now that we have created our SQL Server instance on AWS cloud, we will now launch SQL Server Management Studio on our local machine and login to the newly created database using the credentials we have note down in our previous step. In my case it is as below.

Once you have logged in, you can create required tables, stored procedures, packages etc as per your app requirements.

 

3. Create an EC2 instance

We have our db setup, now we need a server to host our ASP.NET web application. For this we will create a EC2 instance by selecting “Services” in your home page and clicking on “EC2” under Compute category.

Click on “Launch Instance” button on your next page. And then select a suitable Machine Image, in my case I selected “Microsoft Windows Server 2016 Base” for this example and it is a eligible for free tier.

Click on select. In the next page I will retain the default, t2.micro, and will click on “review and launch” button. Like wise you can also configure instance details by go through each settings.

Review your EC2 instance details and click on “Launch” button. You will be asked to provide/create a key pair for your instance. Key pair is a combination of private and public key, we will use this later to connect to our new EC2 instance. You can also proceed without a keypair, but I strongly recommend you to use keypair for security reasons. In my case I will create a new key pair. Note that if you are creating a new key pair, you need to download the newly created private key file and store it securely before proceeding further. Then click on launch.

 

4. Download RDP Client

Now it’s time for us to connect to our EC2 instance from our RDP client so that we can set up the server to host our web application. Once you have created your new EC2 instance you will be taken to the instance screen. Select your instance and click connect option from Actions drop down menu.

Click on “Get Password” button and follow the instructions to see the password for accessing your EC2 instance form RDP. Note down the values for Public DNS, User name and Password. Then click on “Download Remote Desktop File” and save the .rdp file.

Double click on the downloaded .rdp file and it should prompt for a password. In case if you do not have RDP on your localhost, you need to install it to proceed further. Enter the password that we have noted down in our previous step and click OK. Now you should be logged into your EC2 instance using RDP client.

 

5. Set up IIS and .NET

Now you need to set up IIS and .NET framework on your new server. You can follow the steps on the link http://enterprise.arcgis.com/en/web-adaptor/latest/install/iis/enable-iis-2016-components-server.htm.

Once the set up is complete you need to host your web application on IIS. In my case, for my requirement, I had to create a new folder under IIS and set adequate permissions for IIS user in security, and then set host as “mydomain.in” and make it as an application.

 

6. Create an Elastic IP and assign to EC2

We need an Elastic IP if we want our web application to be accessed from internet. To create an Elastic IP, go to home page on your AWS Account, select “Services” and click on EC2 under computer category. Now on your left panel you will find a link to “Elastic IPs”, click on it and then click on “Allocate new address” to create a new Elastic IP. Once created, you can assign the Elastic IP to your EC2 instance.

 

7. Create Route 53

Elastic IP enables us to access our web app from internet using a static IP address but we want to access our web app using a domain name like example.com instead of something like 1.1.12.12. To achieve this we need Route 53 service. Using Route 53 you can either register for a new domain name or you can transfer your existing domain name. You will find Route 53 link under “Network & Content Delivery” as shown below.

 

8. Connecting Route 53 with Elastic IP

Once we have created or transferred our domain with Route 53, we need to set our domain to point to our Elastic IP that in turn points to the web application hosted on IIS. To achieve this, just add an A record with Elastic IP, then Add CNAME record with pointer to A record name. In case you have transferred your domain from another registrar like godaddy.com, note down the NS values in hosted zone and then set the values at domain provider end. And we are done.

Congratulations for hosting your asp.net web application on AWS cloud.