Unleashing the Power of Amazon RDS and EC2: A Step-by-Step Journey!
Hey tech enthusiasts! 👋 Ever wondered how you could create your own relational database on Amazon RDS and connect it to a web app hosted on an EC2 instance? Well, you’re in for a treat! 🍿 Today, I’m going to take you through my experience of doing just that. It’s fun, exciting, and guess what? You don’t need to be a database expert to follow along. Let’s dive in! 🚀
Task 1: Creating an Amazon RDS Database (Say Hello to MySQL!)
First up, I created a MySQL database on Amazon RDS. Why MySQL, you ask? It’s open-source, powerful, and free from licensing fees! Perfect for building apps without breaking the bank.
Here’s how I got started:
From the AWS RDS service, I hit Create database and chose MySQL (version 8.0.32). It’s reliable and supported by AWS’s superpower, Aurora, if you need something more robust later on. 💪
Selected the Dev/Test template (this is the sweet spot for practice labs).
Configured everything: DB identifier as inventory-db, username admin, and password lab-password. Keep it simple!
Chose the smallest instance type (db.t3.micro) and allocated 20 GB of storage. This little guy is all you need to start!
Made sure Multi-AZ deployment was off (no need for high availability right now) and voilà! Hit Create database.
While AWS worked its magic behind the scenes, my database was up and running within minutes! 🌟
Task 2: Connecting the Web Application to the Database
Now that my MySQL database was alive and kicking, it was time to get my web app talking to it. I already had an EC2 instance running an app called "App Server" (sounds fancy, right?).
Here’s the fun part:
I grabbed the Public IPv4 address of my EC2 instance and pasted it into my browser. Guess what? The app was there, but it was empty because it wasn’t connected to the database. Yet.
I went back to the AWS RDS console, found my inventory-db, and copied the Endpoint. This is basically the address where my web app can find the database.
In the app, I entered the Endpoint, database name (inventory), username (admin), and password (lab-password). Hit save, and boom! The app was now fully connected to the MySQL database.
I could now add, edit, and delete inventory records in the app, and the data was securely stored in the Amazon RDS instance. 🎉 No more worries about losing data if the app goes down. #PeaceOfMind
Task 3: Monitoring the Database (Stay Alert!)
With my database running and web app firing on all cylinders, I wanted to keep an eye on its performance. This is where Amazon CloudWatch swooped in like a superhero.
From the Monitoring tab in RDS, I was able to view real-time metrics like CPU utilization, memory usage, and disk I/O. I made some updates in the web app (added new inventory records), and the changes were instantly reflected in the CloudWatch metrics! 📊
This real-time feedback helps you make sure your database is running smoothly. After all, you don’t want things crashing unexpectedly!
Task 4: Stopping the Database (Taking a Breather)
Last but not least, I decided to give my database a break. Did you know you can temporarily stop an RDS instance? 😲 It’s like putting your database to sleep (and saving money while you’re at it).
Here’s what I did:
From the RDS console, I chose Stop temporarily under the Actions menu. This stops the database but keeps the data intact.
Checked the Acknowledgement box and stopped the instance.
And guess what? After a few minutes, the status changed to Stopped. Later, if I want to fire it back up, I can just start it again, reconnect the web app, and continue from where I left off.
The Takeaway
By the end of these tasks, I had a fully functional database, a web app connected to it, and an understanding of how to monitor and manage everything like a pro. Amazon RDS and EC2 make setting up complex infrastructure a breeze, and it’s incredibly satisfying when everything comes together.
So, whether you’re a budding cloud enthusiast or someone with a passion for databases, don’t wait. Try it yourself! You’ll be surprised how fun (and easy) it is to get started. 🚀
Subscribe to my newsletter
Read articles from Aniket Purohit directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Aniket Purohit
Aniket Purohit
I am Devops Engineer working Freelancer and learning skill to master Devops