Deploying AWS RDS Multi-AZ Instance
Tags: aws, database, cloud, cloudskills
Published: 2023-02-09 13:00:00

> **Note:** ✋ This post was originally published on my blog [wiki-cloud.co](https://wiki-cloud.co/en/2022/10/deploying-amazon-rds-multi-az-instance/)

In a [previously article](https://dev.to/aws-builders/high-availability-with-aws-rds-multi-az-3dnd) explained the high availability deployment models presented by Amazon RDS called Multi-AZ that presents two options where you can have one or two standby database instances that are **_Multi-AZ DB instance deployment_** and Multi-AZ DB cluster deployment respectively.

Next, we are going to concentrate on a practical example of the implementation of _**Multi-AZ DB instance deployment**_. The objective of this practical example is to configure the Multi-AZ DB instance schema and we are going to check its functionality by simulating how if there was a failure in the primary database doing a restart and see how the failover is done automatically in the standby database for it this to take the place of the primary.


![Multi-AZ DB Instance Deployment Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w57drl8ue46dv7edlief.png) Image 1 – Multi-AZ DB Instance Deployment Architecture

Before starting with the deployment of the RDS database and the configuration of the Multi-AZ deployment model, you must have previously created and configured the VPC with its respective public and private subnets according to the architecture that has been designed.

For the following practical exercise used the region of _**Europe (Paris) / eu-west-3**_ that has three availability zones and where the VPC that comes by default for this region will be used, later during the creation and configuration of the Amazon RDS instance the respective subnets will be created.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvwn28me4du9h90fyyvo.png)

**<u>Create and Configure Amazon RDS Multi-AZ instance</u>**

We will proceed to search in the AWS Management Console the RDS service and then start the process of creating and configuring the Amazon RDS DB instance by enabling the Multi-AZ scheme.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5xsjtbyrgdwr0l2jjjq8.png)

We select the standard create option which allows us to set configuration options including the Multi-AZ deployment model option.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6azb3wx3l9jshiee0jbj.png)

In this example we are going to select the MySQL database engine to create our instance and select the latest version available in production.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pxnecg8kem5evf22wpn.png)

Now in the templates we select the production that already brings us default values for high availability.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o61lzg7vjh8n1nni952d.png)

The next step is to define the name of the database instance and we configure a master user with its respective password, complying with the parameters defined by the AWS management console.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8sg8fs3mrqxdn33wfe7.png)

The next step is to select the type of instance for the database that includes the number of vCPUs, RAM, and network. For this practice exercise, I selected the instance with the fewest features.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka9dwokjpeqsyhsnae0w.png)

Now we select the storage where our data will be hosted, where we specify the type of disk, its capacity in GiB and the amount of IOPS and if we want our storage to have auto scaling (optional).

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t12vipvs9b3hh0drykpp.png)

Now comes the most important step of this practical exercise and it is the availability and durability part, where we select the Multi-AZ deployment model that is recommended for production scenarios, in this case a standby instance will be created in another availability zone in the region we have selected (Europe – Paris / eu-west-3).

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/312msyb9nuzn5nnuasyx.png)

Finally, we configure the connectivity part, where in this case we select the option to connect to an EC2 instance that was the one that we previously created and we select the VPC that is created by default for this region and we add a new security group for the database enabling port 3306 that will serve us for connectivity tests.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xfyeb6lcup61c233ntfs.png)

I leave the following options by default and click on the “Create Database” button.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rghxvdadrmawaki3pde.png)

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tkp2jg9d9wnv8pplhyg.png)

Once our Amazon RDS (MySQL) database instance has been created, we will also have our subnets and our EC2 instance created to do the respective connectivity tests. It is important to copy the Endpoint that will be used to configure the connection string to our database instance.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwoxx9mm4rd60e69ywti.png)

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8lkqezfdumpcm36hmo6.png)

**<u>Connection and testing Amazon RDS Multi-AZ instance</u>**

For the part of the connection tests and verification of the Multi-AZ deployment model, we are going to start with the part of the connectivity tests from an EC2 instance (Linux) and later we are going to simulate a failure to verify that the Multi-AZ deployment model and the replication works correctly.

The first step is to connect to the EC2 instance that we have created and configured. In my case I will connect through [Putty](https://www.putty.org/) but we can also do it directly from the AWS Management Console.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2vd2xp2k0x109bgzc7j8.png)

Next we are going to run the following command on our EC2 Linux instance to download the updated package lists from the repositories in order to get information about the latest versions of the packages and their respective dependencies.

```sh
sudo apt-get update
```

Now going to install the MySQL client on our EC2 instance to connect to the Amazon RDS (MySQL) instance that we have already created and configured and where we will run some commands to interact with a database and verify the replication. During the execution of the following command, the system asked if we want to continue and we type “Y” and the “Enter” key to continue with the process.

```
sudo apt-get install default-mysql-client
```

Once the MySQL client is installed, the next step will be to connect to our Amazon RDS instance and we will do it through the following command where we put the Endponit that provides us with the Amazon RDS configuration that appears in the AWS management console.

```
mysql -h project-db.cmklzpffazxt.eu-west-3.rds.amazonaws.com -u admin -P 3306 -p
```

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ugrbwy3zbm7c2ls1gsab.png)

Next, we are going to run a series of commands to the MySQL database engine to create a database, create a table, and insert some sample data.

```
SHOW DATABASES;
```

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abxlhn1o7rbnv8vdg0al.png)
```
CREATE DATABASE Company;
```
```
SHOW DATABASES;
```

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7h15nz0mirnu99s6cxui.png)

```
USE Company;
```
```
SHOW TABLES;
```
```
CREATE TABLE Employees (
  employeeId int(11) NOT NULL,
  lastName varchar(50) NOT NULL,
  firstName varchar(50) NOT NULL,
  jobTitle varchar(50) NOT NULL,
  city varchar(20) NOT NULL,
  country varchar(10) NOT NULL
);
```
```
SHOW TABLES;
```

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xmnhqpq2co81nyljxgkd.png)

```
INSERT INTO Employees (employeeID, lastName, firstName, jobTitle, city, country) VALUES (1002,'Murphy','Diane','President', 'Seattle','United States');
INSERT INTO Employees (employeeID, lastName, firstName, jobTitle, city, country) VALUES (1056,'Patterson','Mary','VP Sales', 'London','England');
INSERT INTO Employees (employeeID, lastName, firstName, jobTitle, city, country) values (1102,'Bondur','Gerard','Sales Manager EMEA', 'Berlin','Germany');
INSERT INTO Employees (employeeID, lastName, firstName, jobTitle, city, country) values (1567,'Castillo','Paola','Sales Rep', 'Madrid','Spain');
```
```
SELECT * FROM Employees;
```

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5v28eixmt2qdknolyay.png)

Now we do is execute a command at an interval of every 5 seconds to find out the IP address of the (primary) database that is responding to the requests that an application would make.

```
while true; do host project-db.cmklzpffazxt.eu-west-3.rds.amazonaws.com; sleep 5; done
```

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8yj63052esqx5daqvhs.png)

To verify that the failover is done, we do is a reboot to the Amazon RDS DB instance from the AWS Management Console.

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7yzk6chz9vmq3gaev4s.png)

![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70m1qlklkp45o96jrroy.png)

After the Amazon RDS primary database is restarted, the standby database that contains the replica of the data takes its place to become the primary and begins serving incoming requests.


![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pympatjqtq6531thknou.png)

Finally, we check the Amazon RDS (MySQL) instance events in the AWS Management Console to verify that it has made the failover and the Multi-AZ deployment model has been applied.


![Multi-AZ DB Instance Deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2ooin9sd0ga0mw89m0s.png)

I hope this information is useful.

**Follow me:**

> 👉[Wiki Cloud](http://wiki-cloud.co/) | 👉[Twitter](https://twitter.com/johnbulla) | 👉[LinkedIn](https://www.linkedin.com/in/johnbulla) | 👉[Youtube](https://www.youtube.com/user/johnbulla)