Introduction to RDS in AWS

In this article we are going to learn about Relational Database Service in AWS, called RDS, and will be covering the below topics:
  • Introduction to RDS. 
  • Creating Database using RDS.
  • Accessing RDS database with EC2 instance using MySQL client.

Introduction to RDS

 
RDS is a web service that makes it easier to set up, operate, and scale a relational database in the cloud.
 
RDS is a distributed relational database service and gives you high availability with multiple availability zone deployments.
 
The basic building block of Amazon RDS is the DB instance. A DB instance is an isolated database environment in the cloud. A DB instance can contain multiple user-created databases, and you can access it by using the same tools and applications that you use with a stand-alone database instance.
 
We can create and modify a DB instance by using the AWS Command Line Interface, the Amazon RDS API, or the AWS Management Console.
 
Amazon RDS currently supports the MySQL, MariaDB, PostgreSQL, Oracle, and Microsoft SQL Server DB engines.
 
 
 
Most of the times we use RDS with EC2 instance in the same network.
 

Creating Database Using RDS

 
Go to the RDS Dashboard and click Create Database.
 
 
 
Now once you click on create database, you will need to choose the database type. I am going with MySQL and there are a lot of other options that you can choose to set up your DB.
 
We are going with the Free-Tier and General-Purpose Storage type without enabling auto scaling.
 
 
 
  
 
  
 
Note: In a real environment we really need logs to detect if something goes wrong. So, while setting up we can select the different types of logs which can be published to CloudWatch.
 
 
 
There are lots of options to configure database maintenance, auto scaling, multi-AZ deployments etc. which we can choose as per the requirements.
 
Finally click on Create Database. We can see that our database has been created successfully.
 
 
 
And if I click on the Db Identifier i.e. db-rds, then we can see lot of details like:
 
We can see CloudWatch metrics for RDS service in the monitoring tab.
 
 
 
We can also see CloudWatch alarms here if we set up an alarm on metrics for RDS using CloudWatch and can also see the recent events.
 
 
 
In the CloudWatch Dashboard also we can see the logs.
 
 
 
And if I click this and select the Db then we can see the logs as below:
 
 
 
We can also see the connectivity details like endpoint etc.
 
 
 

Accessing RDS DB With The EC2 Instance

 
As we have selected the database in RDS to be available in the private network only, it cannot be accessed publicly for security reasons. So now we are going to connect to one the EC2 instance named card-web01 as created in one of the previous article Introduction to CloudWatch in AWS.
 
So, after connecting to card-web01 instance, we have run the below command to install the mysql client in order to connect to our database from the internal network as our EC2 instance and RDS database both in North California region.
  1. apt install mysql-client -y 
 
 
As we have seen above in the screenshots, we got an endpoint for the database.
 
 
 
And it connects at port 3306. So, to be able to connect it from our EC2 instance card-web01 we will have to change the inbound rule in the security group of our RDS database.
 
 
 
Let’s now connect to it with the below command as we have already set up the inbound rule.
  1. mysql -h db-rds.ciojus5w3gwa.us-west-1.rds.amazonaws.com -u admin -p  
 
We can see here that we have successfully connected to our MySQL database and with the show databases command we can see all the existing databases.
 
 
 
So, from here we can do any SQL operation either create new database or tables inside the existing database etc.
 

Summary

 
In this article we learned the RDS service of AWS and saw how we can create a database with different options available, how can we actually access it within the internal and can perform different operations with the command line.
 
I hope you find this article helpful. Stay tuned for more … Cheers!!


Similar Articles