Lab 2: Using RDS with ASP.NET Applications

Lab 2: Using RDS with ASP.NET Applications

This is the Lab 02. In here we are going to transfer our localhost website to the AWS RDS SQL database and make the replica of that database. Also at the end of the lab we are configuring the web application to read its data from database replication.

Transferring database to AWS RDS

First we have to go to AWS RDS service console. From there select Launch DB Instance. From the first step of that RDS creation wizard select MySQL. 
Click Next 

Screen Shot 2017-10-11 at 9.32.22 PM.png

Step 2: Select Dev/Test – MySQL that is under free tier 
Select DB instance as – t2.micro
Enable “create replica in different zone”
Click Next

Screen Shot 2017-10-11 at 9.32.33 PMScreen Shot 2017-10-11 at 9.32.44 PM

Step 3: Settings 
Here I am filling my database instance indentifier name as “DinoStoreInstance”
User name : admin 
Password : ******
Click Next

Screen Shot 2017-10-11 at 9.32.51 PM

In the database options, 
Database name should be our database name. “dinostoredb”
Click Next

Screen Shot 2017-10-11 at 9.35.25 PM

After you click next in the previous step you will get the review of settings for you DB instance.
Click Launch DB Instance 

Here you can see my DB instance is in creating progress.

Screen Shot 2017-10-11 at 9.36.38 PM

While DB is creating. I have to do some changes in the security policy. 
In the security policy I am changing the Source address to myIP. So it will take my machine IP. 
Save it
Screen Shot 2017-10-11 at 9.52.12 PM

Connecting RDS to MySQL Workbench

Open a new connection in MySQL Workbench and add following details
Connection name : I am putting some easy for me
Hostname : Endpoint of the DB instance 
User name : as given before
Password : as given before 
Click OK
Screen Shot 2017-10-11 at 9.57.46 PM

In the database I am running a script to delete my previous localhost database and create a new database in the AWS connection. 

After that I have to migrate my data to RDS tables. I have exported CSV file that I have saved. 
So I have imported those data to my table. 
Click apply to process it. 
Screen Shot 2017-10-11 at 10.19.24 PM.png

Creating Replica of main RDS 

We need to create a replica of my main DB. That is to work as a failover and read my data to the site. 
Lets see how we can create a one. 

Selected the main DB instance and from Instance Actions drop down list select “Create read replica”
Screen Shot 2017-10-11 at 10.20.05 PM

After selecting that it will lead us to the next window to select settings and region. 
Keep it in the same region and put the instance identifier name as “DinoStoreInstanceReplica” 
Click Next 
Screen Shot 2017-10-11 at 10.21.53 PM

It will take some time to create the replica and ready both RDS. 

Now I have to connect the replica RDS as well to the MySQL workbench to see everything working fine. 
So I am following the same procedure I went through to connect the main DB. 

Changing the code

Using visual studio I am changing the SQL connection string Server details and user name and password as well. 

Screen Shot 2017-10-11 at 10.31.54 PM

After my SQL connection strings I have added one more connection string for MySQL replica in AWS.

Screen Shot 2017-10-11 at 10.36.43 PM

In my database config file MySQL connection instance I am changing the read images to my MySQL replica in AWS. 
From that my website load will be divided. Reading will access the RDS replica and writing will access the main RDS. 

Screen Shot 2017-10-11 at 10.42.08 PM

I did run the website from localhost and then here I am trying to create an account here to see whether RDS database writing all information 

Screen Shot 2017-10-13 at 7.09.10 PM.png

Also you can see my login button changed to logout when I did registered so lets see the database. 

Screen Shot 2017-10-13 at 7.10.28 PM

In the AWS RDS I can see all the created table under my dinorstore membership table. Thats mean it success. 

Screen Shot 2017-10-13 at 7.11.03 PM.png

I have tried rebooting the main RDS with failover to check whether replica can handle the website and whether login credentials are reading from it. Yes it worked fine. So at the moment my lab steps are doing well. 

Note: When you are applying the S3 links of images to the database make sure you give the right link and make sure link is contain the region details as well. 

Leave a comment