Day 6: Setting Up IAM Roles for EC2 to Manage RDS: Creating and Deleting Records

This project configures IAM roles for EC2 to interact with RDS database allowing it to create and delete records, ensuring efficient access control.

Day 6: Setting Up IAM Roles for EC2 to Manage RDS: Creating and Deleting Records

Introduction to Relational Database Service (RDS)

A relational database in AWS typically refers to managed services like Amazon RDS (Relational Database Service), which supports databases such as MySQL, PostgreSQL, and Oracle. It handles database provisioning, scaling, and maintenance while offering high availability and security features.

Creating RDS

To create a RDS follow the following steps:

Select the database type you want in your system. Here, we are using MySQL.

Select Free-Tier RDS to avoid charges

Create a username and password for the database as shown below.

Here is the database created.

Install mysql-client on ec2 server

Create an ec2 instance and install mysql-client on it as shown below.

Connect EC2 to RDS

Follow the following steps to access RDS through ec2.

Check if RDS is connected to EC2

You can see that there is no database present locally so, it will give error.

Try to connect it to the database you just created with the help of endpoint and port of your database as shown below.

As you can see below, ec2 is failed to connect to the database. So, you need to establish a connection between EC2 and RDS now.

Setting up Connection between EC2 and RDS

Go to Connect compute resources under the database created and click on Setup EC2 Connection as shown below.

Select the EC2 instance you want to connect to RDS as below.

Now you will see a VPC (Virtual Private Cloud) is being set for the EC2 and RDS.

And Connection is setup successfully.

What If EC2 failed to connect still?

If after following above steps, EC2 is failed to connect RDS. You can give RDS access to EC2 through IAM Roles as shown below.

Create Role for AWS service

Create a new Role by selecting AWS Service as EC2.

Select two policies- RDS and CloudWatch

Give Name to this Role and Create it.

Assign Role to EC2

After Creating IAM Role, you need to attach it with EC2 instance. So, go to EC2 dashboard and select instance you want to modify role as shown below.

Choose Role and Update it.

After This step your EC2 instance get full access to RDs and connection will establish successfully.

Create your Database

To create your own database, access to mysql and run the following commands.

Use Database

Create Schema

To use database, you need a schema where you have a specific number of rows and columns. To create the schema go into the database you want and create a table with fields.

Insert Records

Initially, you have an empty database. To insert into it, use insert command as below.

Delete Records

To delete records, use delete command with respect to unique_id of learner as shown.

Hence, you can manage RDS using EC2 server.

This blog demonstrates the creation and usage of RDS via EC2 server. I hope you find it helpful! Stay tuned for more insights on AWS services. Don’t forget to follow for more useful blogs. – Neha Bhardwaj