How to Setup RDS and connect with EC2 in AWS. In this guide you will learn how to create an RDS (Relational Database Service) in AWS and configure it to allow connections from your AWS Instance.
With this method you can have a split website setup by having your programming files on EC2 instance and database on RDS.
Prerequisites
- An active Amazon Web Services account.
- A running EC2 Instance. Learn how to create an AWS EC2 instance.
Important: Make sure you have your RDS and EC2 Instance in the same region. Otherwise you will get latency issues.
Create RDS Database in AWS
Go to your AWS console and navigate to Services >> Database >> RDS.
In the dashboard click Create Database.

Now you can define all your details…
Select your database engine.

Now select template, if you need to get benefited from free tier you can choose Free tier.

Enter a name to identify your RDS instance.
In the Configuration settings enter the master username and password. You can login using this username and password to manage the instance.

Leave everything to default and scroll down to Additional configuration and open that tab.

Here you can create your first database by entering your database name in the Initial database name.
Proceed to configure the automatic backups and retention period as you wish.

Click Create database to create your RDS Instance.
Now your RDS Database Instance will get created.

Now you have created your first RDS Instance.
Configure RDS to allow connections from EC2 Instance
Go to your RDS instance and click the security group in the Connectivity & Security tab.

This will take you to the configure the security group assigned to your RDS instance.
Click the Inbound tab, then click the Edit button to change the rules for your security group.

Change the Type property to MYSQL/Aurora, which will update the Protocol and Port Range to the proper values.
In the value group enter the security group that is used for your EC2 instance.
Click Save.
This rule will allow MySQL access to any EC2 instance with that security group configured.
Become a Certified AWS Professional with this easy to learn course now.
Conclusion
Now you have learned how to setup RDS database instance and allow connections from EC2 instance in AWS.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.
Its worked for me. Same problem I also faced i.e Amazon doc did’t helped much.
THANKS A LOT!!!! It worked perfectly for me ! Why this isnt easy to find in amazons own docs?….
Great
But, if the Database is Postgres, why we have to select the rule for MySQL ?
The ports are different. Also, it is not clear that the inbound rule is inside the Security Group, please specify it a little bit better, otherwise we find ourselves looking for a “Inbound” tab inside the RDS configurations, but it’s not.
Thanks for the effort.