Day 31: Relational Database Service in AWS

Day 31: Relational Database Service in AWS

Hi Everyone!

In the last article, we saw how we can programmatically call AWS services and execute our actions. Let's explore another crucial service in AWS which is AWS RDS. Amazon Relational Database Service (Amazon RDS) is a collection of managed services that makes it simple to set up, operate, and scale databases in the cloud.

What is RDS (Relational Database Service)?

According to official AWS documentation, Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the AWS Cloud. It provides cost-efficient, resizable capacity for an industry-standard relational database and manages common database administration tasks.

Amazon RDS provides the following specific advantages over database deployments that aren't fully managed:

  • You can use the database products you are already familiar with: MariaDB, Microsoft SQL Server, MySQL, Oracle, and PostgreSQL.

  • Amazon RDS manages backups, software patching, automatic failure detection, and recovery.

  • You can turn on automated backups, or manually create your own backup snapshots. You can use these backups to restore a database. The Amazon RDS restore process works reliably and efficiently.

  • You can get high availability with a primary instance and a synchronous secondary instance that you can fail over to when problems occur. You can also use read replicas to increase read scaling.

  • In addition to the security in your database package, you can help control who can access your RDS databases. To do so, you can use AWS Identity and Access Management (IAM) to define users and permissions. You can also help protect your databases by putting them in a virtual private cloud (VPC).

Tasks - Task 1)

  • Create a Free tier RDS instance of MySQL

  • Create an EC2 instance

  • Create an IAM role with RDS access

  • Assign the role to EC2 so that your EC2 Instance can connect with RDS

  • Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.

  1. Open aws consolse > Search for RDS

  2. Click on Create Database \> Select Standard Create > Under “Engine options”, choose “MySQL”

  3. Under Settings, I am providing the following details:

    DB instance identifier: database-example-rd-1

    Credentials Settings:

    Master username: admin

    And provide the password of your choice according to the constraints mentioned.

    Configure other settings like storage, backups, VPC, and security groups according to your requirements. Review the configuration and click “Create Database”.

RDS creation takes a few minutes.

Create an EC2 instance

I am creating an instance named rds-ec2

I am configuring the security group to allow inbound traffic on the MySQL port (default is 3306).

Create an IAM role with RDS access. Assign the role to EC2 so that your EC2 Instance can connect with RDS or you can give required permissions to existing IAM role.

Go to IAM Dashboard > select any role> click on it > Add permissions > In permission policies, attach the permission AmazonRDSFullAccess .

Role modified

Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.

Go to RDS Dashboard > Select the Database you created > Copy the endpoint, port, and master username.

Click on Set up EC2 connection. I have created mu ec2 instance during setting up the RDS so the connection is already established.

Let's connect the instance through SSH and login to RDS DB.

sudo apt-get update sudo apt-get install mysql-client mysql — version

To connect to the RDS instance using the MySQL client and the endpoint address, username, and password, we use the following command:

mysql -h <RDS_ENDPOINT> -P <RDS_PORT> -u <MASTER_USERNAME> -p
#The below details we copied when we created the RDS instance:
#<RDS_ENDPOINT> with the endpoint of your RDS instance
#<RDS_PORT> with the port number (default is 3306)
#<MASTER_USERNAME> with the master username
# ‘-h’ is used to specify the endpoint of MySQL server to which we want to connect

My command will look like this:

mysql -h database-1.cejnfekesyos.us-east-1.rds.amazonaws.com -P 3306 -u admin -p

After running this command, you will be prompted for the password. Give the password you created while creating RDS:

We have created a Free tier RDS instance of MySQL, an EC2 instance, assigned an IAM role with RDS access to the EC2 instance, and connected to the RDS instance from the EC2 instance using a MySQL client.


Thanks for reading ;)