# Relational Database Service in AWS

### [**What is AWS Relational Database Service or RDS?**](https://mizanf123.hashnode.dev/)

Amazon Web Services (AWS) Relational Database Service (RDS) is a cloud-based managed database service offered by Amazon. It provides an easy and scalable way to set up, operate, and scale a relational database in the cloud. RDS abstracts many of the complexities involved in managing traditional relational databases, making it easier for developers to focus on their applications rather than database administration tasks.

With AWS RDS, you can deploy and manage several popular relational database engines, including:

1. MySQL
    
2. PostgreSQL
    
3. MariaDB
    
4. Oracle Database
    
5. Microsoft SQL Server
    

Here are some key features and benefits of AWS RDS:

1. **Managed Service**: AWS RDS handles routine database tasks like provisioning, patching, backup, recovery, and scaling, allowing you to focus on application development.
    
2. **Automated Backups**: RDS provides automated backup and restore capabilities, allowing you to schedule backups and retain them for a specified period. This helps protect your data against accidental loss.
    
3. **High Availability**: RDS offers multi-Availability Zone (AZ) deployments that replicate data across multiple data centers for improved availability and fault tolerance.
    
4. **Scalability**: RDS supports vertical scaling (resizing instances for more or less performance) and horizontal scaling (using Read Replicas for read-heavy workloads) to handle varying workloads.
    
5. **Security**: RDS offers features like encryption at rest and in transit, Virtual Private Cloud (VPC) integration, and fine-grained access control to enhance the security of your databases.
    
6. **Patch Management**: AWS RDS takes care of applying database engine patches and updates, reducing the administrative overhead.
    
7. **Monitoring and Metrics**: RDS provides performance metrics and monitoring through Amazon CloudWatch, allowing you to gain insights into the health and performance of your database instances.
    
8. **Compatibility**: RDS supports popular database engines, making it easier to migrate existing applications to the cloud without major code changes.
    
9. **Cost Efficiency**: By using a managed service, you can potentially reduce operational costs associated with database management and administration.
    
10. **Global Replication**: RDS supports replication features, like Multi-AZ deployments and Read Replicas, which allow you to distribute data across regions for disaster recovery and improved read performance.
    

![Sharding with Amazon Relational Database Service | AWS Database Blog](https://d2908q01vomqb2.cloudfront.net/887309d048beef83ad3eabf2a79a64a389ab1c9f/2019/03/18/sharding-amazon-rds-1.gif align="left")

### [**Why use AWS RDS?**](https://mizanf123.hashnode.dev/)

  
AWS RDS offers a managed and scalable solution for hosting relational databases in the cloud, providing benefits such as automated management, high availability, security features, and scalability. In short, you should consider using AWS RDS to:

1. **Simplify Management**: RDS automates routine database tasks, allowing you to focus on your application development rather than database administration.
    
2. **Ensure High Availability**: RDS supports multi-AZ deployments for data redundancy and failover, minimizing downtime in case of failures.
    
3. **Enhance Security**: RDS offers encryption, VPC integration, and access controls to safeguard your data and comply with security standards.
    
4. **Scale Easily**: RDS allows you to adjust instance sizes for performance or use Read Replicas for read-heavy workloads, scaling your database as needed.
    
5. **Automate Backups**: RDS provides automated backup and restore capabilities, ensuring data durability and easy recovery.
    
6. **Reduce Costs**: By eliminating the need for manual database management, RDS can help lower operational costs.
    
7. **Compatibility**: RDS supports popular database engines, making it seamless to migrate existing applications to the cloud.
    
8. **Monitoring and Insights**: RDS offers performance metrics and monitoring tools to help you optimize database performance.
    
9. **Global Reach**: With features like Multi-AZ deployments and Read Replicas, RDS enables global data distribution for disaster recovery and improved performance.
    

In summary, AWS RDS simplifies database management, enhances availability and security, and provides scalability, making it a valuable choice for hosting relational databases in the cloud.

## [**Task-01:**](https://mizanf123.hashnode.dev/)

[Before Creating RDS Instance let's create an EC2 Instance which we will use to connect to our RDS Instance.](https://mizanf123.hashnode.dev/)

**Step-01:** Go to `AWS Console` &gt;&gt; `Services` &gt;&gt; `EC2`.

[![Screenshot from 2023-07-17 11-56-04](https://user-images.githubusercontent.com/76991475/253866866-2d8d2ab6-302a-49ce-a9fd-85fb562eef6d.png align="left")](https://user-images.githubusercontent.com/76991475/253866866-2d8d2ab6-302a-49ce-a9fd-85fb562eef6d.png)

**Step-02:** Click on `Launch Instance`.

[![Screenshot from 2023-07-17 11-56-37](https://user-images.githubusercontent.com/76991475/253866878-3821920c-0ccc-49ec-a955-0c9671b3002c.png align="left")](https://user-images.githubusercontent.com/76991475/253866878-3821920c-0ccc-49ec-a955-0c9671b3002c.png)

**Step-03:** Give a Name to your Instance and Select `Ubuntu and it Version`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693211021626/fecf654c-abdf-4ef1-b9e9-55ce360d43ee.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693211087155/0229b1d9-3c08-4100-a39c-f52e72f5fd4b.png align="center")

**Step-04:** Select `t2.micro` as your `Instance Type` and also `key pair`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693211222520/eaa37a0e-a8e8-4a64-ace2-811f11b1e21d.png align="center")

**Step-05:** Click on `Review and Launch` and check dashboard for your instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693211398528/f76ec29e-3fb0-4e97-a79e-2ae08507eb66.png align="center")

[**Create a Free tier RDS instance of MySQL**.](https://mizanf123.hashnode.dev/)

* **Step-01:** Go to `AWS Console` &gt;&gt; `Services` &gt;&gt; `RDS`.
    

[![Screenshot from 2023-07-15 21-16-14](https://user-images.githubusercontent.com/76991475/253859523-aeb838aa-625d-4217-9a4c-5f9706ad5590.png align="left")](https://user-images.githubusercontent.com/76991475/253859523-aeb838aa-625d-4217-9a4c-5f9706ad5590.png)

* **Step-02:** Click on `Create database`.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693211695278/a4e36955-0485-41e4-9d58-270668d98eca.png align="center")

* **Step-03:** Select `MySQL` as the `Database creation method`.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693211842129/41b7725f-e4c9-4a6b-b18f-fedc15e98cb5.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693211890602/cb80c699-b566-474c-8435-693bb129b9b6.png align="center")

* **Step-04:** Select **Engine Version** and then Select `Free tier` in `Templates`.
    

[![Screenshot from 2023-07-15 23-11-13](https://user-images.githubusercontent.com/76991475/253859541-43154a0d-f628-49cb-a08a-c27438eab79b.png align="left")](https://user-images.githubusercontent.com/76991475/253859541-43154a0d-f628-49cb-a08a-c27438eab79b.png)

* **Step-05:** Now we will set the `DB instance identifier` and `Master username` and `Master password` and make sure a
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693212244463/8ef6dc24-7e26-4dc2-95f1-b249accb034d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693212293180/196a5932-16ae-4773-8da6-d030273d074b.png align="center")

* **Step-06:** Instance Configuration &gt;&gt; `Burstable classes` &gt;&gt; `db.t3.micro`.
    

[![Screenshot from 2023-07-15 23-13-50](https://user-images.githubusercontent.com/76991475/253859549-e7b8846f-5013-4bb3-a298-647f734bb330.png align="left")](https://user-images.githubusercontent.com/76991475/253859549-e7b8846f-5013-4bb3-a298-647f734bb330.png)

* **Step-07:** `Connectivity` with your `EC2 instance`which we created previously for `RDS connection`.
    

[![Screenshot from 2023-07-17 09-16-40](https://user-images.githubusercontent.com/76991475/253859556-597c1f8d-ace1-4397-90bd-fca51a0dc09d.png align="left")](https://user-images.githubusercontent.com/76991475/253859556-597c1f8d-ace1-4397-90bd-fca51a0dc09d.png)

* **Step-08:** Add the VPC security group (launch-wizard-23) which we will configure in the EC2 instance of the **Security group** &gt;&gt; **Edit inbound rules**.
    

[![Screenshot from 2023-07-17 09-18-59](https://user-images.githubusercontent.com/76991475/253859570-c91476d0-8f75-46bb-8e4c-85e1ae6c8dc0.png align="left")](https://user-images.githubusercontent.com/76991475/253859570-c91476d0-8f75-46bb-8e4c-85e1ae6c8dc0.png)

* **Step-09:** Thus we have created a **RDS instance**.
    

[![Screenshot from 2023-07-17 09-31-06](https://user-images.githubusercontent.com/76991475/253859586-7ae640c1-a294-4473-ab45-cd077eab9806.png align="left")](https://user-images.githubusercontent.com/76991475/253859586-7ae640c1-a294-4473-ab45-cd077eab9806.png)

---

[**Assign the role to EC2 so that your EC2 Instance can connect with RDS Instance.**](https://mizanf123.hashnode.dev/)

* **Step-01:** Go to `AWS Console` &gt;&gt; `Services` &gt;&gt; `IAM` &gt;&gt; `Roles` &gt;&gt; `Create Role` and also select EC2 as the service.
    

[![Screenshot from 2023-07-17 09-56-25](https://user-images.githubusercontent.com/76991475/253859592-7372ee87-83ab-445a-82dc-3efcfa68c04c.png align="left")](https://user-images.githubusercontent.com/76991475/253859592-7372ee87-83ab-445a-82dc-3efcfa68c04c.png)

* **Step-02:** Add the `AmazonRDSFullAccess` policy to the role.
    

[![Screenshot from 2023-07-17 09-56-54](https://user-images.githubusercontent.com/76991475/253859603-52977de4-3292-4fbe-8c3e-103a9a333282.png align="left")](https://user-images.githubusercontent.com/76991475/253859603-52977de4-3292-4fbe-8c3e-103a9a333282.png)

* **Step-03:** Give a name to the role and create the role and review it.
    

[![Screenshot from 2023-07-17 09-58-06](https://user-images.githubusercontent.com/76991475/253859611-e55ac07a-0b3a-4d0c-82a1-e5441162a701.png align="left")](https://user-images.githubusercontent.com/76991475/253859611-e55ac07a-0b3a-4d0c-82a1-e5441162a701.png)

* **Step-04:** Now check whether the role is created or not.
    

[![imageedit_4_5255382338](https://user-images.githubusercontent.com/76991475/253874970-b08fb251-5ad5-496b-945d-35f67452fa0a.png align="left")](https://user-images.githubusercontent.com/76991475/253874970-b08fb251-5ad5-496b-945d-35f67452fa0a.png)

* **Step-05:** Now go to `EC2` and select them `Instance` and click on `Actions` &gt;&gt; `Instance Settings` &gt;&gt; `Modify IAM Role`.
    

[![Screenshot from 2023-07-17 12-48-50](https://user-images.githubusercontent.com/76991475/253875497-26678580-8019-499d-a409-f18fc7994d0d.png align="left")](https://user-images.githubusercontent.com/76991475/253875497-26678580-8019-499d-a409-f18fc7994d0d.png)

* **Step-06:** Select the role which we created previously and click on `Save`.
    

[![Screenshot from 2023-07-17 09-59-46](https://user-images.githubusercontent.com/76991475/253859634-4606fb9d-9793-4cd3-a83b-078695c0f989.png align="left")](https://user-images.githubusercontent.com/76991475/253859634-4606fb9d-9793-4cd3-a83b-078695c0f989.png)

---

[**Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.**](https://mizanf123.hashnode.dev/)

* **Step-01:** Go to `AWS Console` &gt;&gt; `Services` &gt;&gt; `IAM` &gt;&gt; `Roles` &gt;&gt; `Create Role` and also select EC2 as the service.
    

[![Screenshot from 2023-07-17 09-56-25](https://user-images.githubusercontent.com/76991475/253859592-7372ee87-83ab-445a-82dc-3efcfa68c04c.png align="left")](https://user-images.githubusercontent.com/76991475/253859592-7372ee87-83ab-445a-82dc-3efcfa68c04c.png)

* **Step-02:** Add the `AmazonRDSFullAccess` policy to the role.
    

[![Screenshot from 2023-07-17 09-56-54](https://user-images.githubusercontent.com/76991475/253859603-52977de4-3292-4fbe-8c3e-103a9a333282.png align="left")](https://user-images.githubusercontent.com/76991475/253859603-52977de4-3292-4fbe-8c3e-103a9a333282.png)

* **Step-03:** Give a name to the role and create the role and review it.
    

[![Screenshot from 2023-07-17 09-58-06](https://user-images.githubusercontent.com/76991475/253859611-e55ac07a-0b3a-4d0c-82a1-e5441162a701.png align="left")](https://user-images.githubusercontent.com/76991475/253859611-e55ac07a-0b3a-4d0c-82a1-e5441162a701.png)

* **Step-04:** Now check whether the role is created or not.
    

[![imageedit_4_5255382338](https://user-images.githubusercontent.com/76991475/253874970-b08fb251-5ad5-496b-945d-35f67452fa0a.png align="left")](https://user-images.githubusercontent.com/76991475/253874970-b08fb251-5ad5-496b-945d-35f67452fa0a.png)

* **Step-05:** Now go to `EC2` and select them `Instance` and click on `Actions` &gt;&gt; `Instance Settings` &gt;&gt; `Modify IAM Role`.
    

[![Screenshot from 2023-07-17 12-48-50](https://user-images.githubusercontent.com/76991475/253875497-26678580-8019-499d-a409-f18fc7994d0d.png align="left")](https://user-images.githubusercontent.com/76991475/253875497-26678580-8019-499d-a409-f18fc7994d0d.png)

* **Step-06:** Select the role which we created previously and click on `Save`.
    

[![Screenshot from 2023-07-17 09-59-46](https://user-images.githubusercontent.com/76991475/253859634-4606fb9d-9793-4cd3-a83b-078695c0f989.png align="left")](https://user-images.githubusercontent.com/76991475/253859634-4606fb9d-9793-4cd3-a83b-078695c0f989.png)

---

[![imageedit_8_6018864739](https://user-images.githubusercontent.com/76991475/253877184-f467a50d-cd40-49df-a0d3-347f30d4ecbc.png align="left")](https://user-images.githubusercontent.com/76991475/253877184-f467a50d-cd40-49df-a0d3-347f30d4ecbc.png)

* **Step-02:** Now Open the EC2 instance and install the MySQL client.
    

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

```plaintext
mysql --version
```

* **Step-03:** Now Let's configure the **Security group** of the EC2 instance to allow the **inbound traffic** from the RDS instance.
    

[![imageedit_13_6694516260](https://user-images.githubusercontent.com/76991475/253880102-830fa4a1-ceec-4d06-89d1-069c374ed48c.png align="left")](https://user-images.githubusercontent.com/76991475/253880102-830fa4a1-ceec-4d06-89d1-069c374ed48c.png)

* Here we have configured the **port MySQL (3306)** and source as the security group of the RDS instance.
    

[![imageedit_10_2759972710](https://user-images.githubusercontent.com/76991475/253879733-b2080ec0-bfa0-47e8-8047-a6cd74a16cca.png align="left")](https://user-images.githubusercontent.com/76991475/253879733-b2080ec0-bfa0-47e8-8047-a6cd74a16cca.png)

* **Step-04:** Now connect the **RDS instance** with the **EC2 instance** using the **MySQL client**.
    

**COPY**

```plaintext
mysql -h <endpoint-name> -P <port-name> -u <username> -p
```

* **At last, verify your password and we are connected to MySQL.**
    

[](https://user-images.githubusercontent.com/76991475/253859671-59931952-82a0-4c74-bbe6-b3956c5b2007.png)
