Lab 2. Using RDS with ASP.NET Applications

Overview 

In this lab you are going to launch a new MySQL RDS (Relational Database Service) instance to migrate your local MySQL database to Cloud database.

MySQL

MySQL Workbench provides data modeling, SQL development, and comprehensive administration tools for server configuration, user administration, backup, and much more. In this lab MySQL workbench will help us to connect with the RDS instance we create.

Amazon Relational Database Service (Amazon RDS)/ RDS Read Replicas

Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and re-sizable capacity while managing time-consuming database administration tasks, freeing you up to focus on your applications and business. Amazon RDS Read Replicas provide enhanced performance and durability for database (DB) instances. This replication feature makes it easy to elastically scale out beyond the capacity constraints of a single DB Instance for read-heavy database workloads.

By doing this lab you will learn:

  • How to create a RDS Instance
  • How to connect the created RDS instance with your MySQL workbench
  • How to create a RDS Read Replica
  • How to connect your created RDS Read Replica with your MySQL workbench
  • How to compile codes in Visual Studio

The image shown below is the architecture for this lab.

s

To begin with the lab, first you have to create a RDS instance, to create a RDS instance > go to services > select RDS.

When you are on the RDS dashboard click on Get Started Now and click on Launch DB Instance. 

Note: Make a note of the region when you create the instance.

1

Click on MySQL and click on Select.

2

Click on the MySQL radio button which is next to Amazon Aurora and click Next.

3

Select db.t1.micro from the DB Instance Class.

4

Select Yes for Multi-AZ Deployment.
Select General Purpose (SSD) as your storage type.
Type 5GB as your Allocated Storage.
Give the instance Identifier a name as for me i have given ‘DinoStoreInstance‘ as my DB instance identifier name. In Master Username type ‘admin’ and type ‘Walasinsondy1‘ as the password.

5

select ‘Create New Security Group’ from the VPC security Group(s) (The security group allow your current IP address to connect to your instance will be created. This will make it easier for you to connect to the instance and configure it.)

Give the Database name as ‘dinostoredb’.

6

Enable automatic backups by selecting the period of days. As you can see it in the below image i have given 1 day. Click on Launch DB Instance.

7

To Launch the instance it will take 10-15mints please be patient.

8

When the instance is launched the status will show ‘available’. Click on the instance you created in order to get the end point.

9

To go to RDS instance security group click on the instance you created and select details. you will be able to see the security group as a link click on it and you will be directed to security groups.

10

Set the inbound rule to MySQL and select ‘My IP’ under source. click on save.

1112

To connect your RDS instance with the MySQL click on the ‘+’ sign which is next to MySQL connection and the Setup New Connection window will appear, In that window give the following details.
Connection name= AWS DinoStore
Hostname= dinostoreinstance.cduoyuwfybse.us-west-2.rds.amazonaws.com (End point/remove the ‘:3306’)
Username=’admin’
Password= click on store in vault and provide the master password you gave when creating the RDS instance which is ‘Walaginsondy1’.

13

When all the details are provided click on test connection to see if the connection has been establish between cloud and your machine. If it successful you will get a pop up message like which is shown below.

14

To create the tables in cloud use the same script file you used to create table in local machine. Click on > File > Open SQL script choose the script file from your local computer and click open.

15

After opening it. click on execute to execute to it.

16

To add products upload the correct CSV file with the correct imageReferences.

17

Change the imagereferences with the links that is given by the AWS. click on apply.

Screenshot (48)

When its applied click on finish.

18

Now lets create Read Replica of our dinostoredb in the RDS instances, by selecting the dinostoredb and right click to get an action menu and select Create read replica.

19

Give the following details when creating the Read Replica DB instance.

20

DB Instance Identifier=’dinostoreinstancereplica’
Keep the DB instance class the same as the main db =’micro’
Pick a different Availability Zone from the drop down list.
Click on Create Read Replica
It will take 10-15mints to get it created.

21

To connect the read replica you created with your local machine you have to do the same steps as you did it for connecting your dinostoredb. click on the ‘+’ and when the setup new connection window pops-up give the following details.
Connection name=’AWS Dinostore Replica’
Hostname=’dinostoreinstancereplica.cduoyuwfybse.us-west-2.rds.amazonaws.com’ (Endpoint)
Enter the same ‘admin and username you gave while creating the dinostoredb’

22

Click on Test connection to see whether the connection is establish or not.

23

When you are connected go to product table and see if the same information is available or not.

24

Go to your visual studio and click on web.config code and make changes to the use new cloud database by changing the connection strings.

25

the code should be like it is shown above. Add another line copied from the above with the name =’StoreSqlDbReplica’ and the appropriate link to the cloud replica database.

26

In the Default.aspx.cs code, under the ‘//connectstring for MySQL’ comment, change the ConfigurationManager.ConnectionStrings from ‘StoreSqlDb’ to ‘StoreSqlDbReplica’. (This pulls the images from the replica database (reads only) which takes the load off the primary database, and leaves a few more cycles for writes.)

27

To test the new connection open it on your browser.

28

Click on Create account to check out the cloud membership database in MySQL workbench.

29

Fill the details

30

Click on create user when all the fields are filled properly.

31

Now go to your Cloud membership database in MySQL workbench and there you will see tables with the name ‘my_asp’ and click on ‘ my_aspnet_membership

32

34

Now lets make our Primary RDS server and reboot it with failover.

33

Click on the Dinostoreinstance and click on Actions and select reboot.

35

Tick restart with failover. Click on Reboot.

36

While it getting restart you can check if the site is still ok and if its working. Log in using the proper credentials and check if you can login.

37

As you can see the image below it shows that even with a failover you can log in to your account.

38

When all of these steps are done you have completed the lab successfully.

Conclusion:

By the end of this lab you have learned:

  • How to create a RDS Instance
  • How to connect the created RDS instance with your MySQL workbench
  • How to create a RDS Read Replica
  • How to connect your created RDS Read Replica with your MySQL workbench
  • How to compile codes in Visual Studio

Budget Plan

When you are using RDS, you only have to pay for what you use. There is no minimum fee. In this lab i’m using db.t1.micro and it cost me $0.0025 per hour. For this lab i have deployed a multi-Availability Zone as well therefore when you Deploy a Multi-AZ it will cost you bit higher than the actual cost and it would be $0.060 per hour ( Price varies according to different regions). If i create the same db.t1.micro instance in Asia Pacific (Tokyo) it will cost me $0.030 per hour. and there are different kind of DB instances according to your need like db.m1.medium and this will cost you in Asian Pacific (Tokyo) $0.145 per hour.

AWS will give you so many benefits to a reasonable price, you just have to decide which region you want to run your business services.

Advertisements
This entry was posted in Dinostore Labs. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s