> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploying Amazon RDS Multi-AZ and Read Replica, Simulate Failover

> Hands-on lab · 30m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab Details

1. This lab walks you through the steps to launch an Amazon Aurora RDS DB instance with multi-AZ enabled. We will also simulate a database failover from one AZ to another.
2. You will practice using Amazon Aurora.
3. Duration: **1 hour 30 minutes**
4. AWS Region: **US East (N. Virginia) us-east-1.**

### Introduction

#### What is Amazon RDS?

##### Amazon RDS

* Amazon Relational Database Service (Amazon RDS)  is a Relational Database service that offers high availability and throughput.
* Amazon RDS comes with great features that include **Multi-AZ** feature and **Read Replica** that ensures no data loss.
* Amazon RDS also provides you high scalability where you can scale up and scale down depending on your needs.
* Amazon RDS provides you with six familiar database engines which include **MySQL, Amazon Aurora, PostgreSQL, MariaDB, Oracle Database and SQL Server.**

##### Multi-AZ

* Multi-Availability zone (Multi-AZ) is a feature that comes with Amazon RDS that  provides you with high availability and durability for Database instances.
* When we are opting for the Multi-AZ database instance, it will automatically create a Primary DB instance and parallelly replicate the data to the standby instances in different availability zones in that region. However, we can't access the standby instances, unlike primary instances.
* The **main purpose** of Multi-AZ is to provide a **failover option** for primary RDS instances.
* Amazon RDS uses the Failover mechanism for Oracle, MYSQL, MariaDB and PostgreSQL instances.
* **The RDS Failover process** happens automatically and is **managed by AWS** without human intervention.
* Amazon RDS **uses** the concept of **SQL Mirroring** for Replicating data to standby instances in the different availability zones, and **both primary and standby** instances **use the same endpoint.**

#####

##### Reasons for Failover

* The failover process will take place due to one of the following reasons, occurring in the primary instances:

  * Host Failure
  * DB instance class modification.
  * Instance rebooting
  * Availability zone failure
  * RDS maintenance

##### Conditions for enabling Multi-AZ on RDS

* A **minimum of two different availability zones** should be present in a **DB subnet group** where you are launching your Primary DB instance.

##### Amazon Aurora and Read Replica

* Amazon Aurora is the DB instance, which is a little different when comparing to the above-mentioned Instance types.
* Aurora uses the concept of a DB cluster, where the primary instance replicates its data across different availability zones.
* In the case of a primary instance failure, Aurora automatically launches its primary instance from the replicated instance in a different availability zone.
* Multi-AZ on Aurora clusters makes RDS replicate or provision a replica of the master database to a different availability zone within a Region.

###

### Architecture Diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/001.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=2138a6ac3d8c5850126a5a749fe7762e" alt="" width="2105" height="1052" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/001.png" />

### Task Details

1. Sign into the AWS Management Console.
2. Launch an EC2 Instance
3. Create a Security Group for RDS instance
4. Create an Amazon Aurora database with Multi-AZ enabled
5. Connecting to the Aurora (MySQL) database on RDS
6. Connecting the EC2 Server to RDS
7. Execute Database Operations via SSH
8. Forcing a Failover to Test Multi-AZ
9. Testing the Failover Condition
10. Deleting AWS resources

### Launching Lab Environment

1. To launch the lab environment, click on the **Start Lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM username**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

**Note** : You can only start one lab at any given time

## Lab guide

### Lab Steps

#### Task 1: Sign in to AWS Management Console

1. Click on the Open Console button, and you will get redirected to AWS Console in a new browser tab.

2. On the AWS sign-in page,

   * Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. Otherwise, you cannot proceed with the lab.
   * Now copy your **Username** and **Password** in the Lab Console to the **IAM Username and Password** in AWS Console and click on the **Sign in** button.

3. Once Signed In to the AWS Management Console, make the default AWS Region as **US East (N. Virginia) us-east-1.**

> **Note :** If you face any issues, please go through [**FAQs and Troubleshooting for Labs**](https://play.whizlabs.com/site/task_support/faqs-and-troubleshooting).

####

#### Task 2: Launch an EC2 instance

In this task, we are going to launch an EC2 instance which will be used for connecting to the Amazon Aurora RDS DB instance later in the lab.

1. Navigate to **EC2** by clicking on the **Services** menu in the top, then click on **EC2** in the **Compute** section.

2. Click on **Instances** from the left sidebar and then click on **Launch instances**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/002.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=48e67d50cc7e4b42d2f9062c057f3b95" alt="" width="2457" height="499" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/002.jpg" />

3. Name : Enter **MyRdsEc2server.**

4. **For Amazon Machine Image (AMI):** In Quick Start menu, select **Amazon Linux 2023 kernel-6.1 AMI.**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/003.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=ef118638d5e753a121fb7d4973382c2f" alt="" width="1186" height="651" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/003.png" />

5. **For Instance Type:** select **t2.micro**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/004.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=76760624b511a00fbb1355f392f80f9a" alt="" width="1106" height="261" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/004.png" />

6. **For Key pair:** Select **Create a new key pair**

   * Key pair name: **MySSHKey**
   * Key pair type: **RSA**
   * Private key file format: **.pem**

     **Note: If you are using putty, select the Private key file format as .ppk**

7. Select **Create key pair** Button.

8. In Network Settings, Click on **Edit**:

* Auto-assign public IP: **Enable**
* Select **Create new Security group**
* Security group name : Enter ***MyEC2Server\_SG***
* Description : Enter ***Security for ec2 server to connect with RDS***

  * **To add SSH:**
  * Choose Type: **SSH**
  * **Source**: select **Anywhere**

9. Click on **Advanced Details .** Under the **User data** section, enter the following script, (which installs MySQL):

\#!/bin/bash

# Download the MySQL repository package

```python theme={null}
wget https://dev.mysql.com/get/mysql80-community-release-el9-5.noarch.rpm
# Install the MySQL repository package
sudo dnf install mysql80-community-release-el9-5.noarch.rpm -y
# Enable the MySQL community repository
sudo dnf repolist enabled | grep "mysql.*-community.*"
# Install MySQL
sudo dnf install mysql -y
```

**Note: After pasting the user data, make sure to remove extra spacing.**

10. Keep rest thing Default and Click on **Launch Instance** Button.

11. Select **View all Instances** to View the Instance you Created

12. After 1-2 minutes, the **Instance State** will become **running** as shown below:

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/005.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=c9b99b7a5d15c0fe1a6c6faa91046274" alt="" width="2438" height="308" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/005.jpg" />

13. **Select** the EC2 Instance and **copy** the Private IPv4 address. Note down **IPv4 Private IP address**  in your text editor, navigate to the EC2 Dashboard and look in the instance details.

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/006.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=f15a2523aed885c0ea1baf9de58caa69" alt="" width="2463" height="911" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/006.jpg" />

#### Task 3: Create a Security Group for RDS instance

In this task, we will create a security group specifically for the Amazon Aurora RDS instance which ensures that the RDS instance has appropriate network security settings by allowing access only through the MySQL/Aurora port (3306) from any IP address (0.0.0.0/0).

1. Make sure you are in the **N.Virginia** Region.

2. Navigate to **EC2** by clicking on the **Services** menu available under the **Compute** section.

3. On the left panel menu, select the security group under the **Network & Security** section.

4. Click on the **Create security group** button.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/007.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=84effcbaae4ea34a212c0c50c1a8998d" alt="" width="2462" height="475" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/007.jpg" />

5. We are going to create a Security group for RDS with 3306 port number enabled.

   * Security group name : Enter **rds-maz-SG**
   * Description : Enter **Security group for RDS Aurora**
   * VPC : Select **Default VPC**

     <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/008.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=33403d88fa24d1cfed9b29a9dff58bb2" alt="" width="1806" height="603" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/008.jpg" />

* Click on the **Add rule** button under **Inbound rules.**

  * Type : Select **MYSQL/Aurora**
  * Source : Select **Anywhere IPv4**

6. Leave everything as default and click on the **Create security group** button.

#### Task 4: Create an Amazon Aurora database with Multi-AZ enabled

In this task, we will create an aurora database using AWS RDS service. The database is configured with Multi-AZ deployment, which replicates data to a standby instance in a different availability zone, providing high availability and durability.

1. Make sure you are in **US East (N.Virginia) us-east-1** Region.

2. Navigate to **RDS** under the **database** section of the **Services** menu.

3. Click on **Databases** in the left Panel.

4. Click on **Created database** button and choose **Full Configuration** Option.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/009.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=e9077ca00b5c0e834ab4994254372197" alt="" width="2354" height="369" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/009.jpg" />

5. Next, we'll configure the database on the **Create Database** Page

   * Choose a **Database Creation Method:**

     * Select **Standard Create**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/010.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=8f8498ac15abe65eab721b44265b0bea" alt="" width="683" height="121" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/010.jpg" />

* In **Engine options:**
* Engine type  : Choose **Aurora (MySQL Compatible)**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/011.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=f48dbdcafa8280774d09b239e5ee5e6d" alt="" width="2251" height="1269" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/011.jpg" />

* Available versions: Leave it as **Default**
* Choose **Template: Dev/Test**
* Fill in the required details for the database (Aurora Cluster Settings)
* **DB cluster identifier:** Specify cluster name **MyAuroraCluster**
* Give the following details in the **credential settings**
* Master Username: Enter **WhizlabsAdmin**
* ?Credentials management: Select **Self managed**
* Master password: Enter **Whizlabs123**
* Confirm password: Enter **Whizlabs123**
* **Note:** This is the username and password used to log into your database. Please make note of them.

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/012.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=b9f006e9966301a7fb6b1a46ccc391be" alt="" width="2212" height="1176" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/012.png" />
* Choosing **DB instance size**
* DB instance class: Choose **Burstable classes (includes t classes)**
* **Select db.t3.medium instance.**

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/013.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=49a40cf9f346fb1f8cadee3c8ae774fa" alt="" width="1812" height="408" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/013.jpg" />
* **Availability and Durability**: Choose Multi-AZ deployment: **Create Aurora Replica or Reader node in a different AZ**  as shown below:

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/014.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=f839cec1d45f9c60db80db846f3402b0" alt="" width="1541" height="321" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/014.jpg" />
* **Connectivity**

  * Choose the Default VPC

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/015.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=254d4ebd8fd07e444fbfde3f6a629ce7" alt="" width="1904" height="479" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/015.jpg" />
* Additional connectivity configuration

  * Subnet group\*\*: Default\*\*
  * Publicly accessible: **Yes \{IMPORTANT}**
  * Existing VPC security groups :

    * Remove the Default security group, which is selected by default :

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/016.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=6dfba5f728bb06bc4693fbd31113fb1b" alt="" width="599" height="231" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/016.jpg" />

* Select **rds-maz-SG** for the dropdown.(This is the security group which you have created in the beginning)

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/017.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=a1244c029b36b82fdb6310f9c4c6fed3" alt="" width="492" height="253" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/017.jpg" />

* Under Monitoring, **uncheck** monitoring option.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/018.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=0c65d45bb0a5f4180cc8ac85469973e3" alt="" width="1582" height="638" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/018.png" />

* Select the **Additional configuration** present at the bottom of the page and enter the following details\*\*:\*\*

  * Database options

    * Initial database name:  Enter **whizlabsrds**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/019.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=ca1365691bc799809974d5208efdf35f" alt="" width="1939" height="184" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/019.jpg" />

* Leave other settings **as default**

6. Once the details above have been filled in, click on **Create database** button.
7. It will take around **10-15 minutes** for the database to be created. Please wait until database status changes from **creating** to **Available**.
8. Once the database has been created, you should see the following page:

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/020.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=3200ef74ba6982725f9bd61e8b2ed7be" alt="" width="2378" height="518" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/020.jpg" />

* Similar to the screenshot, you should be able to see that our database launched in multiple AZs, namely **us-east-1c and us-east-1a**

#### Task 5: Connecting to the Aurora (MySQL) database on RDS

Now we have successfully launched Aurora RDS with Multi-AZ enabled. To connect to the new Aurora database, we need the **endpoint.**

1. Click on the **RDS cluster name** and then navigate to **Connectivity & security** to find the endpoint of your **Master (Writer) and Reader** instances, with which you can connect to your DB instance.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/021.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=ea7ae4aa62acba00122f484f0a0dee9a" alt="" width="2378" height="979" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/021.jpg" />

* The endpoints you see to be similar to these examples:

**Master (Writer): myauroracluster.cluster-c2tbqtanuaea.us-east-1.rds.amazonaws.com**

**Reader**: **myauroracluster.cluster-ro-c2tbqtanuaea.us-east-1.rds.amazonaws.com**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/022.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=83aa47a549b0566d18f1663bf828f6fb" alt="" width="2378" height="518" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/022.jpg" />

**Note: Please carefully look at the role of the DB instance (reader vs Master (Writer)) and their respective availability zones. (here us-east-1c and us-east-1a)**

#### Task 6: Connecting the EC2 Server to RDS:

In this task, we are going to establish connectivity between the EC2 instance created earlier and the Amazon Aurora RDS database. By modifying the security group of the RDS instance, they allow access from the EC2 instance, enabling communication between the two resources.

1. Now we need to connect the RDS with EC2 instance in order to eventually connect with the Aurora database.

2. Navigate to **RDS** available under the **Database** section of the **Services** menu.

3. Click on **Master (writer) database** and click on the security group name in this example it is **rds-maz-SG** under VPC security groups as shown below:

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/023.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=d56ff37ac899b1cd5bba9cd7c8ee4462" alt="" width="2378" height="819" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/023.jpg" />

4. It will open the Security Group page. Click on **Inbound rules.**

* Click on **Edit inbound rules**. The MySQL rule will already exist.
* Click on **Add rule** button.

  * Type: Select **MYSQL/Aurora**
  * Source: **Paste** the Private IP address of your **MyRdsEc2server** EC2 instance.
  * **Delete** the old rule and then Click on **Save rules** button.

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/024.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=a6e7bf385aa88bef1380660924598ef2" alt="" width="2821" height="809" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/024.jpg" />

#### Task 7: Execute Database Operations via SSH

In this task, we are going to execute database operations on the Amazon Aurora RDS database. By SSHing into the EC2 instance and accessing the database using MySQL, they can create tables, insert data, and perform queries.

1. Navigate to the EC2 Dashboard and select the instance created.
2. Once the instance is launched, Select **EC2 Instance Connect** option and click on **Connect** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/025.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=188c8537292448486666403f8fcc0211" alt="" width="2936" height="1310" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/025.jpg" />

3. Please follow the steps in [SSH into EC2 Instance](https://play.whizlabs.com/site/task_support/ssh-into-ec-instance) for more option to SSH.
4. Switch to the root user using the command :

   ```
   sudo su
   ```
5. Log into the RDS instance using the below command:

* **mysql -h myauroracluster.cluster-cjp5t9qppjnx.us-east-1.rds.amazonaws.com -u WhizlabsAdmin** **-p**
* **Syntax: mysql -h \<Hostname> -u \<username> -p**
* **Note:** Make sure to change the above **Master (Writer)Cluster endpoint** and **Username** with yours.
* Host name : **myauroracluster.cluster-cpoz6c7903cx.us-east-1.rds.amazonaws.com (Master(Writer)cluster endpoint)**
* Username : Enter **WhizlabsAdmin**
* Password : Enter **Whizlabs123** (Use yours incase you changed the password while creating RDS)
* You should now be able to log into the database,

6. List all Databases using the below command. You will see the database **whizlabsrds** created while launching the RDS cluster.

   ```
   show databases;
   ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/026.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=87b89f989a17fa5b0ee9aa0b95b1058f" alt="" width="1532" height="667" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/026.png" />

7. Now create the database in the **Master(Writer) RDS** as given in the screenshot. We'll create a demo database named **auroro\_db.**

   ```
   Create database auroro_db;
   ```

8. Select the newly-created database:

```
use auroro_db;
```

9. List all Databases:

   ```
   Show databases;
   ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/027.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=eeef90a5615ad4dc3fefbc54380c8e27" alt="" width="488" height="395" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/027.png" />

10. Next we'll create a table named **students** and insert few rows of data using list of commands:

```python theme={null}
CREATE TABLE students ( subject_id INT AUTO_INCREMENT, subject_name VARCHAR(255) NOT NULL, teacher VARCHAR(255),start_date DATE, lesson TEXT,PRIMARY KEY (subject_id));
```

Select \* from students;

Show tables;

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/028.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=446b08ea2356b55e54c965691ac4ab64" alt="" width="1894" height="411" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/028.png" />

11. Insert data into the table:

    ```
    INSERT INTO students(subject_name, teacher) VALUES ('English', 'John Taylor');
    ```

    ```
    INSERT INTO students(subject_name, teacher) VALUES ('Science', 'Mary Smith');
    ```

    ```
    INSERT INTO students(subject_name, teacher) VALUES ('Maths', 'Ted Miller');
    ```

    ```
    INSERT INTO students(subject_name, teacher) VALUES ('Arts', 'Suzan Carpenter');
    ```

12. Now you can view the contents of the table student using the below command:

    ```
    select * from students;
    ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/029.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=89e8316d62fcb80b9311ff459a1f771f" alt="" width="1109" height="596" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/029.png" />

13. Exit from mysql console use the below command:

```
exit;
```

#### Task 8: Forcing a Failover to Test Multi-AZ

In this task, we are going to simulate a failover scenario in which the master instance fails, and the read replica takes over as the new master.

1. Navigate to **RDS Database** and in Database section Select **Master(Writer)** Instance and in Actions dropdown, click on failover

2. To test if Multi-AZ is working, we will create a situation where master fails and the read replica has to become the new Master(Writer).

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/030.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=bcf2fe626b6008fff0fe0a24f58990e4" alt="" width="2380" height="620" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/030.jpg" />

3. On the next screen, confirm the Failover.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/031.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=fd5eeee771fa2bc51d27cec7f17c5557" alt="" width="2934" height="526" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/031.jpg" />

4. Wait for a few minutes for the RDS instances to failover.

* **(i.e Master (Writer) becomes Reader and Reader becomes Master (Writer) as shown below)**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/032.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=f3f7cb871698a244e5709eb55f9628a3" alt="" width="2333" height="522" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/032.jpg" />

#### Task 9: Testing the Failover Condition

In this task, we are going to the new master instance and verify the presence of the database, table, and data created earlier. This step ensures that the failover was successful, and the new master instance is functioning as expected.

1. Now connect to RDS with new Master endpoint

   * Copy the endpoint of the **new Master(Writer)cluster** and replace it with your endpoint link.

**Mysql -h \<endpoint> -u \<username> -p** and press **\[Enter]**

* **mysql  -h myauroracluster.cluster-ro-cjp5t9qppjnx.us-east-1.rds.amazonaws.com -u WhizlabsAdmin -p**
* Password\*\*:\*\* Enter **Whizlabs123**

2. You will be **able to Log** into MySQL and check for the database and table created in the master DB instance before the failover.

* You can notice the resources created on the original master db are present, implying that the Failover worked successfully.

```
Show databases;
```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/033.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=507d41a2713192d8ce1d6e217a03da40" alt="" width="562" height="363" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/033.png" />

3. Now check the existence of table named **students and data**  (that we created earlier in the lab):

   ```
   use auroro_db;
   ```

   ```
   select * from students;
   ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/034.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=31bbe28147c96794d59f5ad2f947f98c" alt="" width="919" height="434" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/034.png" />

> ##### Do you Know?
>
> With Multi-AZ deployment, your database's transaction logs are synchronously replicated to the standby instance. This ensures that your data is durable and protected against potential data loss in the event of a primary instance failure.

1. Once the lab steps are completed, please click on the **Validation** button on the left side panel.
2. This will validate the resources in the AWS account and shows you whether you have completed this lab successfully or not.

#### Task 10: Delete AWS Resources

##### Terminate EC2 Instance

1. Navigate to EC2 by clicking on the **Services** menu in the top, then click on the **EC2** in the **Compute** section.
2. All the EC2 Instances will be listed here,

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/036.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=6a8556505c1d91e549291515e40abcc1" alt="" width="2465" height="336" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/036.jpg" />

1. To terminate the EC2, perform the following task:

   * Select **MyRdsEc2server,**
   * Click on **Instance state**
   * Select **Terminate instance**

     <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/037.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=59ee4a39e04f917149e26e0ff30aaff1" alt="" width="1812" height="452" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/037.png" />
2. Finally, Click on **Terminate** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/038.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=b9fea34fed72dfe932c7337f6b207cc6" alt="" width="1636" height="624" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/038.jpg" />

1. EC2 Instance will be terminated.

##### Delete RDS DB Instances

1. Navigate to **RDS** by clicking on the **Services** menu available under the **Database** section.
2. Click on **Databaes**
3. It will list all the RDS databases

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/039.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=05f6a048cfe1287d0da613402542405e" alt="" width="1246" height="374" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/039.png" />
4. Let's delete the **Reader** first, Click on **Actions,** and select **Delete**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/040.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=3eaec926b13c981a00041757e2e2523a" alt="" width="2363" height="600" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/040.jpg" />

1. To delete we have to perform several tasks:

   * Type **delete me** to confirm
   * And finally, click on the **Delete** button below.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/041.jpg?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=e3b24d87761d372e8f92a8cdce2a9add" alt="" width="1197" height="775" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/041.jpg" />
2. Now it's time to delete **Writer** first, Click on **Actions,** and select **Delete**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/042.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=f41a5a3c50ed2fdef2b13a7d5b9c22ee" alt="" width="1248" height="302" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/042.png" />
3. To delete we have to perform several tasks:

   * Uncheck the option of **Create final snapshot**
   * Check the **acknowledge** option.
   * Type **delete me** for confirmation
   * And finally, click on the **Delete** button below.

     <img src="https://mintcdn.com/ip-cloud-architect-pathway/wwYjlvXuP--kOMyQ/images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/043.png?fit=max&auto=format&n=wwYjlvXuP--kOMyQ&q=85&s=a6c56d3e3e37b8be6e73493fd802b334" alt="" width="750" height="709" data-path="images/labs/deploying-amazon-rds-multi-az-and-read-replica-simulate-failover/043.png" />
4. It will take around 4 minutes to delete the database instance, you can end the lab now.

### Completion and Conclusion

* You have successfully used the AWS management console to create an Amazon Aurora MySQL database with Multi-Az enabled.
* You have created an Amazon Aurora database on RDS.
* You have successfully connected to the Amazon Aurora database and tested the failover condition with Multi-AZ enabled.
* You have successfully validated the lab.

### End Lab

1. Sign out of AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End lab** from the IP Lab Portal dashboard.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Launch an EC2 Instance** — Check whether an EC2 Instance is launched or not.
* **Validate EC2 Instance Type t2.micro** — Check whether the EC2 instance type is t2.micro.
* **Launch EC2 AMI type Amazon Linux** — Check whether the EC2 instance is launched using an Amazon AMI.
* **Create RDS Cluster** — Check whether RDS Cluster is created or not.
* **Force RDS Database Failover** — Check whether RDS database failover is done or not.

## Related help

* [FAQs and Troubleshooting](/aws-saa/support/faqs-and-troubleshooting)
* [SSH into EC2 Instance](/aws-saa/support/ssh-into-ec2-instance)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.