Relational Database Service in AWS
Table of contents
- Introduction:
- Key Features of AWS RDS
- Use Cases
- Pricing Model
- Task-01
- Create a Free tier RDS instance of MySQL
- Create an EC2 instance
- Create an IAM role with RDS access
- Assign the role to EC2 so that your EC2 Instance can connect with RDS
- Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.
- 1. Create a Free Tier RDS MySQL Instance
- 2. Create an EC2 Instance
- 3. Create an IAM Role with RDS Access
- 4. Assign the IAM Role to the EC2 Instance
- 5. Connect EC2 to RDS Using MySQL Client
- Create a Free tier RDS instance of MySQL
- Create an EC2 instance
- Create an IAM role with RDS access
- Assign the role to EC2 so that your EC2 Instance can connect with RDS
- Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.
- 1. Create a Free Tier RDS MySQL Instance
- 2. Create an EC2 Instance
- 3. Create an IAM Role with RDS Access
- 4. Assign the IAM Role to the EC2 Instance
- 5. Connect EC2 to RDS Using MySQL Client
- Deploy WordPress website on AWS
- Task-02
- As WordPress requires a MySQL database to store its data, create an RDS.
- To configure this WordPress site, you will create the following resources in AWS:
- An Amazon EC2 instance to install and host the WordPress application.
- An Amazon RDS for MySQL database to store your WordPress data.
- Set up the server and post your new WordPress app.
- 1. Create an RDS MySQL Database
- 2. Launch an EC2 Instance for WordPress
- 3. Install LAMP Stack on the EC2 Instance
- 4. Install WordPress
- 5. Connect WordPress to RDS MySQL
- 6. Access the WordPress Installation
- 7. Optional: Secure Your WordPress Installation (Let’s Encrypt)
Introduction:
Amazon Relational Database Service (RDS) is a fully managed relational database offered by Amazon Web Services (AWS). It simplifies the setup, operation, and scaling of relational databases in the cloud. RDS helps developers focus on their applications by handling routine database management tasks like backups, patching, and replication.
Key Features of AWS RDS
Support for Multiple Database Engines
RDS supports popular relational database engines, including:Amazon Aurora
MySQL
PostgreSQL
MariaDB
Oracle Database
Microsoft SQL Server
Automated Backups
AWS RDS provides automated backups, point-in-time recovery, and manual snapshots for data protection. This ensures data is safe and can be restored in case of accidental loss or failure.High Availability
RDS offers high availability with the Multi-AZ (Availability Zone) deployment option. This creates a synchronous standby replica in a different Availability Zone to ensure minimal downtime.Read Replicas
To improve performance and scalability, RDS offers read replicas. These replicas handle read-heavy workloads and help distribute traffic without affecting the primary database's performance.Automatic Scaling
RDS allows vertical scaling, meaning you can increase or decrease instance size to match your workload demands. Amazon Aurora (a fully managed RDS database engine) offers serverless scaling options.Security
RDS integrates with AWS Identity and Access Management (IAM) for access control and Amazon Virtual Private Cloud (VPC) for network isolation. It also supports encryption for data at rest and in transit using AWS Key Management Service (KMS).Monitoring and Performance Insights
AWS provides detailed performance monitoring with CloudWatch metrics and RDS Performance Insights, helping you analyze and optimize database performance.
Use Cases
Web and Mobile Applications: RDS is suitable for managing relational databases in scalable, secure, and highly available environments.
E-Commerce Applications: The service ensures low-latency data access and real-time inventory management.
Data Warehousing: RDS can be used for reporting, aggregation, and structured data analytics.
Pricing Model
RDS offers pay-as-you-go pricing, meaning you pay only for the database instance hours, storage, and I/O operations consumed. AWS also offers Reserved Instances and Savings Plans to optimize costs.
Task-01
Create a Free tier RDS instance of MySQL
Create an EC2 instance
Create an IAM role with RDS access
Assign the role to EC2 so that your EC2 Instance can connect with RDS
Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.
Follow the step-by-step process below to complete the task:
1. Create a Free Tier RDS MySQL Instance
Login to AWS Console: Navigate to the AWS Management Console.
Open RDS Service:
Choose "Create Database."
Select MySQL as the engine.
Choose Free Tier in the "Templates" section.
Configure the Database:
Database name:
mydb
(example).Master username:
admin
.Set a password or enable auto-generated passwords.
Instance Specifications:
Choose db.t2.micro (eligible for Free Tier).
Storage: 20 GB (General Purpose SSD).
VPC and Security Group:
Ensure that the database is in a default or accessible VPC.
Create or use an existing security group that allows inbound MySQL traffic (Port 3306).
Database Options:
Disable "Public Access" unless explicitly needed.
Enable automatic backups if desired.
Create Database: Click "Create Database" and wait for the instance to be provisioned.
2. Create an EC2 Instance
Open the EC2 Service:
- Click "Launch Instance."
Instance Details:
AMI: Choose Amazon Linux 2 or Ubuntu (Free Tier eligible).
Instance Type:
t2.micro
.Key Pair: Create or select a key pair.
Security Group Configuration:
Allow inbound SSH (Port 22) access from your IP.
Ensure the security group allows outbound traffic to Port 3306 (MySQL).
Launch the Instance: Wait for the instance to be ready.
3. Create an IAM Role with RDS Access
Open the IAM Service:
- Go to "Roles" and click "Create Role."
Trusted Entity:
- Select "AWS Service" and choose EC2.
Attach Policy:
- Add the policy AmazonRDSFullAccess (or a custom policy with specific permissions).
Create Role: Give the role a name
EC2RDSRole
and complete the creation.
4. Assign the IAM Role to the EC2 Instance
Go to the EC2 Dashboard:
Select the EC2 instance you created.
Click "Actions" → "Security" → "Modify IAM Role."
Attach the
EC2RDSRole
role to the instance.
5. Connect EC2 to RDS Using MySQL Client
Retrieve RDS Credentials:
In the RDS Console, go to your MySQL instance and click "View Details."
Note the Endpoint and Port (e.g.,
mydb.xxxxxx.rds.amazonaws.com
).
Connect to EC2 via SSH:
Use your key pair to SSH into the EC2 instance:
ssh -i "your-key.pem" ec2-user@your-ec2-public-ip
Install MySQL Client (if not installed):
For Amazon Linux:sudo yum install mysql -y
For Ubuntu:
sudo apt update sudo apt install mysql-client -y
Connect to the RDS MySQL Database:
Use the MySQL client to connect to the database:mysql -h your-rds-endpoint -P 3306 -u admin -p
Enter the Password: Enter the RDS password to establish the connection.
Verification: Once connected, you can run a simple query to verify:
SHOW DATABASES;
This completes the setup and connection of an EC2 instance with an RDS MySQL instance on AWS.
Deploy WordPress website on AWS
Task-02
As WordPress requires a MySQL database to store its data, create an RDS.
To configure this WordPress site, you will create the following resources in AWS:
An Amazon EC2 instance to install and host the WordPress application.
An Amazon RDS for MySQL database to store your WordPress data.
Set up the server and post your new WordPress app.
Here’s a step-by-step guide to deploying a WordPress site on AWS using an EC2 instance and RDS for MySQL.
1. Create an RDS MySQL Database
Go to RDS Console:
Navigate to the AWS RDS service in the AWS Console.
Click "Create Database".
Choose Database Engine:
Select MySQL.
Choose "Free Tier" as the deployment option.
Database Settings:
DB Name:
wordpress
.Master Username:
admin
.Password: Create a strong password or auto-generate one.
Instance Type:
Choose db.t2.micro (Free Tier eligible).
Storage: 20 GB (General Purpose SSD).
Connectivity:
Ensure that the RDS instance is in the same VPC as your EC2 instance.
Enable Public Access (for demo purposes).
Ensure that the security group allows inbound traffic on Port 3306 (MySQL).
Create the Database:
- Click "Create Database" and wait for the RDS instance to become available.
2. Launch an EC2 Instance for WordPress
Go to EC2 Console:
- Click "Launch Instance".
Instance Configuration:
Choose Amazon Linux 2 or Ubuntu (Free Tier eligible).
Instance type:
t2.micro
.Create or select an existing key pair.
Security Group Configuration:
Allow inbound SSH (Port 22) for admin access from your IP.
Allow inbound HTTP (Port 80) for web traffic.
Ensure outbound access to Port 3306 to allow connection to RDS.
Launch the Instance:
- Click "Launch" and wait for the instance to be ready.
3. Install LAMP Stack on the EC2 Instance
Connect to the EC2 instance via SSH:
ssh -i "your-key.pem" ec2-user@your-ec2-public-ip
Update Packages:
sudo yum update -y
Install Apache:
sudo yum install httpd -y sudo systemctl start httpd sudo systemctl enable httpd
Install PHP and MySQL Client:
sudo amazon-linux-extras enable php8.0 sudo yum install php php-mysqlnd -y
4. Install WordPress
Download WordPress:
wget https://wordpress.org/latest.tar.gz tar -xvzf latest.tar.gz sudo cp -r wordpress/* /var/www/html/
Set Correct Permissions:
sudo chown -R apache:apache /var/www/html sudo chmod -R 755 /var/www/html
Restart Apache:
sudo systemctl restart httpd
5. Connect WordPress to RDS MySQL
Get RDS Endpoint:
- Go to the RDS Console and copy the endpoint of your MySQL database.
Edit WordPress Configuration:
Rename the sample configuration file:
sudo mv /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
Open the file for editing:
sudo nano /var/www/html/wp-config.php
Update the following lines with your RDS database details:
define('DB_NAME', 'wordpress'); define('DB_USER', 'admin'); define('DB_PASSWORD', 'your-rds-password'); define('DB_HOST', 'your-rds-endpoint:3306');
Save and close the file.
6. Access the WordPress Installation
Open a web browser and navigate to
http://your-ec2-public-ip
.You should see the WordPress installation page.
Follow the steps to:
Set a site title.
Create an admin username and password.
Complete the installation.
7. Optional: Secure Your WordPress Installation (Let’s Encrypt)
To enable HTTPS:
Install Certbot:
sudo amazon-linux-extras enable epel sudo yum install certbot python3-certbot-apache -y
Generate SSL Certificate:
sudo certbot --apache
Follow Prompts to set up SSL for your site.