How to Access an AWS RDS Instance from an EC2 Instance.

How to Access an AWS RDS Instance from an EC2 Instance.

EC2 Instance.

An EC2 instance functions much like a virtual machine (VM) and can run various operating systems such as Linux, Windows, or custom AMIs (Amazon Machine Images). You can choose from a wide range of instance types optimized for different workloads, such as compute-intensive, memory-intensive, or storage-heavy applications. EC2 instances can scale up or down based on your workload requirements. You can start with a single instance and scale out to hundreds or thousands as needed. This is possible through features like Auto Scaling and Elastic Load Balancing (ELB).

Amazon RDS.

Amazon RDS (Relational Database Service) is a fully managed database service provided by Amazon Web Services (AWS). It makes it easy to set up, operate, and scale a relational database in the cloud. RDS automates common database management tasks such as backups, patch management, scaling, and failover, allowing you to focus more on application development rather than managing the database infrastructure.

RDS supports a variety of popular relational database engines:

  • Amazon Aurora (AWS’s own high-performance database)
  • MySQL
  • PostgreSQL
  • MariaDB
  • Oracle Database
  • SQL Server

STEP 1: Navigate the EC2 Instance and Create the instance.

Screenshot 2024 12 18 16402511

STEP 2: Navigate the Amazon RDS .

  • Click create database.
  • Select the standard create and select mariadb.
Screenshot 2024 12 18 113037

STEP 3: Click on free tier.

  • Enter the password.
Screenshot 2024 12 18 113056
Screenshot 2024 12 18 113111

STEP 4: Click on connect to an EC2 compute resource and select your instance.

Screenshot 2024 12 18 113133

STEP 5: Select db.t3.micro.

  • Click on create.
Screenshot 2024 12 18 115428
Screenshot 2024 12 18 152147

STEP 6: Accessing EC2 with SSH.

sudo su -
sudo apt install mariadb-server
systemctl enable mariadb
systemctl start mariadb
Screenshot 2024 12 18 155326
Screenshot 2024 12 18 155721
Screenshot 2024 12 18 155840
Screenshot 2024 12 18 16015311

STEP 7: Connect the instance use the following command.

mysql -h <RDS endpoint> -p 3306 -u <username> -p

Screenshot 2024 12 18 161648
Screenshot 2024 12 18 163005

Conclusion.

Amazon RDS is a powerful service for managing relational databases in the cloud. It eliminates the overhead of database management tasks such as hardware provisioning, patching, backups, and scaling. With support for multiple database engines, high availability features, and robust security, RDS is an ideal choice for businesses of all sizes to manage their data in a cost-effective and efficient manner. Whether you’re running a small application or a large enterprise system, Amazon RDS makes it easier to deploy and manage relational databases at scale.

Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *