Table of contents
- Introduction
- AWS-Relational Database Service
- Key Features:
- Tasks: Setting Up MySQL RDS and EC2 Connectivity :)
- Task 1: Create a Free tier RDS instance of MySQL
- Task 2: Create an EC2 instance
- Task 3: Create an IAM role with RDS access
- Task 4: Assign the role to EC2 so that your EC2 Instance can connect with RDS
- Task 5: Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.
- Conclusion :)
Introduction
In this blog post, we delved into the powerful capabilities of Amazon Relational Database Service (Amazon RDS) - a fully managed database solution by AWS. This marks the 44th day of our 90DaysOfDevOps journey. We embarked on a journey to create a free-tier MySQL RDS instance. Additionally, we seamlessly integrated an EC2 instance with RDS, paving the way for a secure and efficient connection.
AWS-Relational Database Service
Amazon Relational Database Service (Amazon RDS) is a fully-managed database service provided by Amazon Web Services (AWS). It simplifies the process of setting up, operating, and scaling relational databases in the cloud. Amazon RDS supports several popular database engines, including:
MySQL
PostgreSQL
MariaDB
Oracle Database
Microsoft SQL Server
Amazon Aurora (which is a MySQL- and PostgreSQL-compatible database built for the cloud)
Key Features:
Automated Backups: RDS automatically backs up your database and retains backups for a user-defined period. This ensures data durability and provides a point-in-time recovery option.
High Availability: RDS offers Multi-AZ deployments for high availability. In a Multi-AZ configuration, the database is automatically replicated in a different Availability Zone to provide fault tolerance.
Scalability: You can easily scale your database instance up or down based on your application's requirements.
Security: RDS offers features like network isolation, encryption at rest, and in-transit, as well as automated software patching to enhance the security of your databases.
Automated Software Patching: RDS manages database engine updates, including backups and automated failover, to help maintain the health of your database.
Affordable: Paying for the consumed resources is enough in the case of Amazon Relation Database Services. There are no long term commitments or up-front charges and, therefore, one of the cost- effective services.
Tasks: Setting Up MySQL RDS and EC2 Connectivity :)
Task 1: Create a Free tier RDS instance of MySQL
Step 1: Log in to your AWS Management Console.
Step 2: Navigate to the RDS service.
Step 3: Click on "Create database".
Step 4: Select "MySQL" as the database engine.
Step 5: Choose "Free Tier" in the "Templates" section.
Step 6: Configure other settings (DB instance size, storage, instance identifier, master username, password, additional configuration ).
Setting > DB instance identifier
Setting > credential
Instance configuration
I selected t2.micro for free tier
Storage
20GB storage are freely available for the free tier.
Connectivity > public access
Under connectivity, VPC (Virtual Private Cloud) concept are there. For now make the vpc as default and
I gave the public access so that i can access the RDS from the anywhere
Additional configuration
Note: If you do not specify a database name, Amazon RDS does not create a database.
Step 7: Click "Create database".
Note: The creation of the RDS instance may take more than 5 minutes, and sometimes even up to 10 minutes. Please be patient and allow AWS the necessary time for the successful setup of the RDS instance.
Step 8: Congratulation
You successfully created your first RDS
Task 2: Create an EC2 instance
Log in to your AWS Management Console.
Navigate to the EC2 service.
Click on "Launch Instance" to start the instance creation process.
Choose an Amazon Machine Image (AMI) based on your requirements (e.g., Amazon Linux 2).
Select an instance type (e.g., t2.micro, which is part of the free tier).
Configure the instance details (e.g., number of instances, network settings, etc.)
Configure security groups to control inbound and outbound traffic (you'll need to allow traffic on port 22 for SSH access).
Review the instance details and click "Launch."
Choose an existing key pair or create a new one for SSH access.
Finally, click "Launch Instances
For more detailed information on AWS EC2 and account setup, you can refer to this comprehensive guide:
Task 3: Create an IAM role with RDS access
Sign in to the AWS Management Console:
- Go to the AWS Management Console and sign in with your AWS account credentials.
Open the IAM Console:
Navigate to the IAM service.
Create a New Role:
Click on "Roles" in the left-hand menu and then click on the "Create role" button.
Choose the Trusted Entity:
Select "AWS service" as the trusted entity.
Select EC2 and then click "next"
Attach Policies:
In the "Permissions" step, search for policies that provide access to RDS resources. You can either select existing policies like
AmazonRDSfullAccess
or create a custom policy.click Next
Name the Role:
Provide a name for the role, e.g.,
RDSAccessRole
, and optionally provide a description.
Review:
- Review the settings and policies you've selected. If everything looks correct, click "Create role."
Successfully created
Task 4: Assign the role to EC2 so that your EC2 Instance can connect with RDS
Open the EC2 Console
Sign in to the AWS Management Console, go to the EC2 service.
Locate the EC2 Instance
Find the EC2 instance that you want to assign the IAM role to.
I newly ceated the instance named "my-db-demo"
Stop the Instance (if necessary)
If the instance is running, you might need to stop it to modify its configuration. Right-click on the instance, select "Instance State", and then click "Stop".
Associate IAM Role
Select the EC2 instance in the console.
Click on "Actions" and go to "security".
Click on "Modify IAM Role".
Choose the IAM Role
In the "Attach/Replace IAM Role" dialog box, select the role you created earlier (e.g.,
RDSAccessRole
).Click "update IAM role" to attach the role.
Start the Instance (if it was stopped)
If you stopped the instance, right-click on it, select "Instance State", and then click "Start".
Task 5: Once the RDS instance is up and running, get the credentials and connect your EC2 instance using a MySQL client.
SSH into EC2: Use the SSH command to connect to your EC2 instance. Replace
<your-key.pem>
and<your-ec2-instance-ip>
with your actual key file and EC2 instance IP:ssh -i <your-key.pem> ec2-user@<your-ec2-instance-ip>
Install MySQL Client: Update package information and install the MySQL client:
sudo apt-get update sudo apt-get install mysql-client
Check MySQL Version: Verify that the MySQL client is installed correctly:
mysql --version
Connect to RDS: Use the MySQL client to connect to your RDS instance.
Replace
<RDS-endpoint>
,<port>
,<username>
, and<password>
with your actual RDS endpoint, port, username, and password:RDs-endpoint
port is 3306
username and password were created above when creating the RDS
mysql -h <RDS-endpoint> -P <port> -u <username> -p
Congrulation
You successfully connected EC2 with the MySQL RDS
Conclusion :)
With each step, we achieved significant milestones in setting up a robust AWS environment. We successfully created a free-tier MySQL RDS instance, forged an EC2 instance, and established a secure bridge between them. This accomplishment not only expands our capabilities in cloud computing but also lays a strong foundation for future endeavours in AWS services.
Thank you for diving into this blog with me! I trust you found the information both helpful and enlightening. To stay updated on the latest in DevOps ๐, make sure to follow me. Remember, staying informed means staying ahead in the dynamic world of DevOps!
Feel free to connect with me on:
For more updates and engaging discussions on DevOps, let's connect! ๐ #DevOpsCommunity
Happy Learning! Keep pushing those boundaries! ๐