🔧 Hands-on: Connecting an EC2 Instance to Amazon RDS MySQL (Including Read Replica)

📌 Objective
Understand AWS RDS fundamentals through hands-on practice
Create and connect a MySQL RDS instance securely
Implement backups using snapshots
Configure and test Read Replicas
Restore a database from a snapshot
🧱 Prerequisites
Before starting, ensure the following are ready:
AWS Account
Basic knowledge of EC2, VPC, and Security Groups
Default or custom VPC with:
- At least two private subnets (required for RDS subnet group)
Step 1️⃣ Create DB Subnet Group (Pre-requisite)
RDS requires a DB Subnet Group with subnets in at least two AZs.
Steps:
Go to RDS → Subnet groups
Create a subnet group
Select your VPC
Add private subnets from 2 AZs

Step 2️⃣ Create RDS MySQL DB Instance
Configuration Used:
Engine: MySQL
Version: Free-tier eligible
Template: Free Tier
DB instance identifier: Give name
Credentials: Username & password
Connectivity:
VPC: Same as EC2
Public access: ❌ No
DB Subnet Group: Created earlier
Availability:
- Single AZ (initially)







Step 3️⃣ Launch EC2 Instance
Steps:
Launch Amazon Linux EC2
Place it in a public subnet
Attach a Security Group allowing:
- SSH (22) from your IP
Use the same VPC as RDS

Step 4️⃣ Configure Security Groups
EC2 Security Group
- Allow SSH (22)
RDS Security Group
Allow MySQL (3306)
Source: EC2 Security Group (not IP-based)
This ensures secure internal communication.

Step 5️⃣ Install MySQL Client on EC2
After connecting to EC2 via SSH, I installed the MySQL client using the following commands:
# Switch to root
sudo su -
# Install dependencies
yum install wget -y
# Download MySQL repo
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
md5sum mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
# Install MySQL
yum install mysql-server -y
sudo yum install mysql -y --nogpgcheck
sudo yum install mysql-connector-java.noarch -y --nogpgcheck

Step 6️⃣ Connect EC2 to RDS MySQL
Used the RDS endpoint to connect:
mysql -h rds-endpoint-name -P 3306 -u username -p
After login, I executed basic SQL commands to verify connectivity:
Create database
Create table
Insert records
Select data


Step 7️⃣ Create Snapshot (Backup)
Snapshots are manual backups of the DB instance.
Steps:
Go to RDS → Databases
Select DB instance
Actions → Take snapshot
Provide snapshot name

Step 8️⃣ Create Read Replica
Read Replicas help scale read-heavy workloads.
Steps:
Select primary DB
Actions → Create read replica
Same region
Separate DB identifier
Key Points:
Uses asynchronous replication
Has a separate endpoint
Used only for READ operations
Step 9️⃣ Connect to Read Replica
To connect to the read replica, I used only the read replica endpoint:
mysql -h read-replica-endpoint-name -P 3306 -u username -p
Verified:
SELECT queries work
INSERT/UPDATE not allowed

Step 🔟 Create New DB Instance from Snapshot
Steps:
Go to RDS → Snapshots
Select snapshot
Actions → Restore snapshot
Configure DB identifier & settings
This creates a new independent DB instance.
✅ Key Learnings
RDS is a fully managed database service
Subnet groups are mandatory for RDS
EC2-to-RDS access must be via Security Groups
Snapshots enable point-in-time recovery
Read Replicas scale reads without affecting writes
📎 Conclusion
This hands-on lab helped me gain real-world exposure to AWS RDS MySQL architecture, security, backups, and scaling strategies. Practicing these steps strengthened my understanding of how production-grade databases are designed on AWS.
Follow for more:
Linkedin: https://www.linkedin.com/in/devops-samarjeet/
#AWS #CloudComputing #DevOps #AWSArchitecture #EC2 #VPC #ALB #NATGateway #AWSBeginner #CloudLearning #InfrastructureAsCode #AWSHandsOn #TechBlog

