Using RDS with ASP.NET Applications
We have already shifted the Images and
other files of DinoStore to the Cloud. Now in this lab, we are going to shift
the database from local MySQL to the AWS RDS.
Amazon Relational Database Service (RDS)
RDS is the relational database service from Amazone. Amazon RDS provides you six familiar database engines to choose from, including Amazon Aurora, Oracle, Microsoft SQL Server, PostgreSQL, MySQL, and MariaDB.
I have launched an RDS instance in my AWS account.
We have to select the region we need as per our requirement, I have selected Sydney as my region because it is the nearest one for me. I am using MySQL on my local computer so that I have selected MySQL as my RDS Engine.
Instance class I have selected a microDB storage I selected SSD, 5GB. Then I have given a username and password for the instance. I have given the database name as dinostoredb and enabled automatic backups by selecting a period of days to 0.
In the security group option select to create a new security group and in the inbound rules I have added my IP to be allowed. I have copied the endpoint connection string from the dinostoredb instance detail.
endpoint string in the hostname. Then given the username and password which was used for the RDS instance and saved it. I have tested the connection and it was successful then I clicked ok to connect to the RDS.
I have connected to the DB in the cloud and used a script to create tables in the cloud database.
Then I have log back tho the local database and exported the product list from there as CSV format and imported it into the cloud database.
I can view the imported data in my cloud table.
Next, I am going to create a read replica of the RDS Instance in a different availability zone. This will act as a read-only copy of the current database, this will give our database a better redundancy and load balancing option. Here I am creating a replica and redirecting the website to use the images from there to make a load balancing.
I have created a replica by selecting the dinostoredb and right click to get an action menu to select the replica option. Then I have followed the same steps as for the previous database, but I have selected a different availability zone for the new database.
Now we can find two databases in the RDS.
I have made a new connection for the replica database as well.
I have received the same copy of the main database here in the replica.
Then I have redirected Visual Studio program to use new databases by editing the details in Web config file.
Then I have redirected the storage link to replica and for all other activities use the main database, in the Visual Studio Default.aspx file.
Then I have built the project and tested the website. Initially, I received an error then I have foud out an error in the database details in web config. I changed the database details then built again and this time, it was successful.
Now I am logged in as the new user. Let us check the database now.
Here in the users table, I can see the newly created user.
Now we can check the replica by restarting the main database.
I have rebooted the database while rebooting I have refreshed the website and found that the website was available all the time.
No comments:
Post a Comment