Day 44: Relational Database Service in AWS

Day 44: Relational Database Service in AWS

Β·

4 min read

πŸ™ Introduction:

In this blog, we will go deep dive into what Amazon RDS is and how to use it to create, configure, and connect to MySQL databases in the cloud.

Amazon RDS

Amazon RDS, or Relational Database Service, is a cloud-based service provided by Amazon Web Services (AWS) that makes it easier to set up, operate, and scale a relational database. In simple terms, it allows you to use a managed database without worrying about the underlying hardware, software, and administrative tasks.

Instead of dealing with the complexities of database management, such as hardware provisioning, database setup, patching, and backups, you can use Amazon RDS to handle these tasks for you. This lets you focus more on your application and data, while Amazon RDS takes care of the heavy lifting associated with running a relational database. It supports various popular database engines like MySQL, PostgreSQL, Oracle, SQL Server, and MariaDB.

🎯Task: 1

Create a Free tier RDS instance of MySQL

  • Sign in to the AWS Management Console and open the Amazon RDS console

  • Go to the RDS dashboard and then choose Create database

  • On the Create database page, choose Standard create and then choose MySQL as the database engine.

  • Under the Templates section, choose the Free tier

  • Under the Settings section, enter a name for your database instance

  • Under the Credentials Settings section, enter a username and a password for your database

  • Under the Instance configuration section, choose Burstable classes (includes t classes) and then choose db.t2.micro as the instance type

  • Under the Storage section, choose General Purpose (SSD) as the storage type and enter 20 as the allocated storage. disabled the Storage autoscaling

  • Under the Connectivity section, Select Connect to an EC2 compute resource and select the EC2 instance that you want to connect.

Under the DB subnet group section, Select Automatic setup

Under the VPC security group (firewall) Section, choose Create new, this will create a new security group that allows inbound traffic on port 3306 (the default port for MySQL) from any IP address

  • Under the Database authentication section, choose Password authentication as the authentication method. This will allow you to connect to your database using the username and password that you entered earlier

  • Click on Create Database

  • Database created

Create an EC2 instance

  • Go to the Amazon EC2 console

  • Click Launch Instance, Choose a Linux AMI

  • Choose an instance type, such as t2.micro and Choose Key-pair(login)

  • Choose a VPC and subnet

  • Launch the instance

Edit Inbound rules to allow inbound traffic from MySQL (e.g. port 3306).

Create an IAM role with RDS access

  • Go to the IAM console, Select Roles Click on Create role

  • In the Trusted entity type section, Select the AWS service & in the Use case Section, Select EC2

  • Attach the AmazonRDSFullAccess policy

  • Enter a unique name for the role

Click Create role, Role is created

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

  • Go to the EC2 console

  • Select the instance Click on Actions --> Security -->Modify IAM Role

  • Choose the IAM role you just created, Click Update IAM role

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

  • Go to the RDS console

  • Select the database you just created, Click on Connectivity & security and note the endpoint address

  • SSH into your EC2 instance using a terminal

  • Install a MySQL client
sudo apt update -y
sudo apt install mysql-client -y

  • Connect to the RDS instance using the MySQL client and the endpoint address, username, and password
mysql -h <endpoint address> -P <port.no> -u <username> -p
mysql -h my-mysql-db.cknvc5na3ufk.us-west-2.rds.amazonaws.com -P 3306 -u admin -p
SHOW DATABASES;

Now we are connected to the MySQL database on the RDS

πŸ‘‹ Conclusion :

In this blog, we cover how to use Amazon RDS to set up and manage MySQL databases in AWS, in the next blog we will cover AWS Advanced Topics.

Thank you for reading!

Contact me on Linkedin

Check out my GitHub for more resources πŸ“š

Β