Lab 5: Adding EC2 Virtual Machines and Deploying the Web App

Lab 5: Adding EC2 Virtual Machines and Deploying the Web App

In the lab 5 we are creating the IAM role for the use of web server and then I am going to launch two EC2 instances for web server and queue server. End of this lab I am going to transfer my web application to AWS instance and run it on cloud server. 

Lets start. 

We want to create roles that access to other Amazon services so that applications running on EC2 instances don’t have to have credentials baked into the code.

Go to the IAM from AWS services and click policies from left pane and click policy generator. 

Screen Shot 2017-10-18 at 7.16.15 PM

Im creating a policy using following information. 
Effect: Allow 
AWS Service: Amazon DynamoDB
Actions: DeleteItem, DescribeTable, GetItem,PutItem,UpdateItem
Click Add statement 

Screen Shot 2017-10-18 at 7.20.19 PM

Second policy,
Effect:Allow
AWS Service: Amazon SQS
Actions: DeleteMessage, DeleteMessageBatch,GetQueueUrl, SendMessage, SendMessageBatch
Click Add statement and Click Next Step

Screen Shot 2017-10-18 at 7.30.24 PM

From the next step I am creating the IAM role. 
Click Create Role

Screen Shot 2017-10-18 at 7.31.49 PM

Select AWS Service and then click EC2 
Click Next

Screen Shot 2017-10-18 at 7.32.18 PM

Next step is to add permissions to the role. 
Select it and click Next.

Screen Shot 2017-10-18 at 7.33.26 PM

As I mentioned earlier in the post we need two servers to run web server and queue server. Now we will install those two servers here. 

Go to AWS EC2 and select create instance. 
Select the EC2 AMI as Microsoft Windows Sever 2012 R2 (Free tier) 

Screen Shot 2017-10-18 at 7.35.10 PM

Select t2.micro and click next 

Screen Shot 2017-10-18 at 7.35.32 PM

Here, I am selecting the role we have created earlier. 
Then click Next

Screen Shot 2017-10-18 at 7.37.51 PM

I am adding a tag as a name. 
Click Next

Screen Shot 2017-10-18 at 7.38.30 PM

Select create new security group. 
In here after the RDP protocol I am adding HTTP and select the source as anywhere. 
Click Review and Launch.

Screen Shot 2017-10-18 at 7.42.00 PM

Now I am creating the Queue server. 
Select the Windows Server 2012 R2 (Free tier) 

Screen Shot 2017-10-18 at 7.43.11 PM

Select t2.micro as the instance type
Click next

Screen Shot 2017-10-18 at 7.43.20 PM

Select IAM role as “WebServerRole” 
Click next

Screen Shot 2017-10-18 at 7.43.39 PM

Leaving the default storage and click next

Screen Shot 2017-10-18 at 7.43.47 PM

I am adding a tag here as a name. 
Click Next

Screen Shot 2017-10-18 at 7.44.08 PM

I am creating a new security group here and click Next

Screen Shot 2017-10-18 at 7.47.03 PM

Click Launch 

Screen Shot 2017-10-18 at 7.47.12 PM

From key pair windows I am creating a new key that I can use for both servers. 

Screen Shot 2017-10-18 at 7.47.23 PM

You can see one instance is already created and one other is pending. 
Right click on the WebServer and click Connect

Screen Shot 2017-10-18 at 7.47.56 PM

Here I am uploading my key pair key and getting the password for the instance. 

Screen Shot 2017-10-18 at 7.48.33 PM

Next thing is. I have to run IIS on the server to deploy my web application. 
To do that I am installing IIS using the Active Directory features. 
Click Add roles and features in server dashboard and click Next 

Screen Shot 2017-10-18 at 7.51.33 PM

Select Role-Based or Features based installation

Screen Shot 2017-10-19 at 9.20.42 PM

Click Next 

Screen Shot 2017-10-19 at 9.20.51 PM

In the server roles list, Scroll down and find Web Server (IIS) Select it and click next. 

Screen Shot 2017-10-19 at 9.21.09 PM

In the features list I am going to install ASP.NET 4.5. This web application developed using ASP.NET and we need ASP.NET feature in the server. 
Click Next

Screen Shot 2017-10-19 at 9.21.45 PM

From the Role Services list I am selecting Windows Authentication option. 

Screen Shot 2017-10-19 at 9.24.09 PM

Review all the details and click Install

Screen Shot 2017-10-19 at 9.25.21 PM

Here you can see my IIS is installed and running perfectly

Screen Shot 2017-10-19 at 9.27.18 PM

Now I have to move my web application to my newly install Windows Server instances. Till now my web application runs on the localhost. So now I am moving it to cloud. 

Right click on the NET702.DinoStore project that is opened in the Visual Studio. 
In the list down menu click Publish

Screen Shot 2017-10-19 at 9.30.22 PM

Published Method : File System,
Name : RDP
Target Location : Saving location (Local)
Click Next 

Screen Shot 2017-10-19 at 9.36.05 PM

Select Publish

Screen Shot 2017-10-19 at 9.38.08 PM

After web application is successfully published to the folder you have selected, we have to move that to our cloud server.

I am copying and pasting my published folder to the server (Location: Local Disk (C:) –> Inetpub –> wwwroot)
Why I am copying my folder to here ? Because IIS server is running on this location and if you want to run website on IIS then site should be here.

Screen Shot 2017-10-19 at 9.47.41 PM

In the Server Manager Dashboard click Tools and select IIS. 
In the left pane (Connections) Select the default web sites and right click on the web folder that I just copied. 
Click Convert to Application 

Screen Shot 2017-10-19 at 9.50.54 PM

In the AWS security groups I am editing the RDS security rule.  
Click the RDS security group and click edit in the inbound rules

I need to add two more rules.  I am going to add the security group that is created for the web server and queue server. 
Add rule — > All traffic –> copy and paste web server security group name 
Add rule –> All traffic –> copy and paste queue server security group name 
Click Save

Screen Shot 2017-10-19 at 9.58.47 PM

Now go back to the EC2 instances (Web Server) go to the uploaded web application folder and open the Web.config file via notepad. 
Remove the access keys and secret keys in the sections of <providers> and <appSettings>

Save the file

Screen Shot 2017-10-19 at 10.00.40 PM

Screen Shot 2017-10-19 at 10.01.33 PM

NB: the SDK gets these automatically as part of the role we set up earlier. Open up IE on your server and drop in this URL: http://169.254.169.254/latest/meta-data/iam/security-credentials/WebServerRole

You should see temporary credentials, but these are from the _role_ you created.

Screen Shot 2017-10-19 at 10.03.32 PM

Go to the IIS manager and explore the web application and select the Default.aspx file and click Browse. 

Screen Shot 2017-10-19 at 10.07.02 PM

Now you can see the Dino Store website is up and running. 

Screen Shot 2017-10-19 at 10.10.27 PM

I am going to try to reach web server and see what is happening. So I am going to copy and paste my EC2 web server instance link on my computer browser. 
Working fine, I am getting my website thats mean my Instance is working fine as the web server. 

Screen Shot 2017-10-20 at 1.01.53 PM.png

Now we have to publish the DinoStore Oder processing project. To do that, 
Right click on the NET702.DinoStore.OderProcessor and click publish 

Screen Shot 2017-10-19 at 10.24.07 PM

Select the publishing location and click next.

Screen Shot 2017-10-19 at 10.28.42 PM

Select – From a CD-ROM or DVD-ROM 
Click Finish 

Screen Shot 2017-10-20 at 1.21.53 PM.png

So when its done, automatically published folder will be opened. I have to copy this folder to my instance and run the setup. 

Screen Shot 2017-10-19 at 10.32.38 PM

I have copied my publish folder to the Web server. 
You can add the setup program file to StartMenu and startup programs as well. Then the program will always run at the startup. 

Double click on the setup file and click Install.

Screen Shot 2017-10-19 at 10.37.06 PM

After the installation, CMD will prompt for the queue processing. 

Now I am running my website and adding some items to the cart and checkout for buying. After I entered all billing and credit card details I am going to check my web server situation. 

Screen Shot 2017-10-19 at 10.13.37 PM

Here it is, Now here I can see one Queue message received and deleted. Thats meant this picked by server and added to the DB. 

Screen Shot 2017-10-19 at 10.42.35 PM

My newly added item is saved on the database now. 

Screen Shot 2017-10-20 at 1.28.10 PM

This is the end of Lab 5.

Now we have moved our localhost website to the cloud and running it on the cloud using our cloud web server. 

  • Issues:
    When you are published the website project, check all the files and NuGet packages are published properly. Sometime it will not published properly. 
  • Update all NuGet packages that you have installed. Specially DyanamoDBv2. 

 

Leave a comment