Day 4: Deploying a Two-Tier Web App with MySQL on Amazon RDS
Elevate Your Cloud Skills with a Two-Tier Application on AWS
Welcome to Day 4 of our AWS mastery journey! Today, we're embarking on an exciting project - deploying a two-tier application. Tier 1 features a Dockerized web app, while Tier 2 hosts a MySQL server on Amazon RDS. Let's dive into the world of containers, AWS, and seamless cloud integration.
Setting the Stage: Unleashing the Power of Docker and AWS
Defining Your Project: Start by conceptualizing your project. Our goal is to create a two-tier application where the first tier is a Dockerized web app, and the second tier is a MySQL server hosted on Amazon RDS.
Tier 1: Dockerized Web App
Installation: Begin by installing Docker on your EC2 instance. This will be the backbone of your containerized web app.
Cloning the Repository: Clone this repository which contains the Dockerfile.
Image Creation: Execute
docker build
to create an image from your Dockerfile. This encapsulates your app and its dependencies.
Tier 2: MySQL on Amazon RDS
Configuring Amazon RDS:
Database Instance Creation: Navigate to the AWS Management Console, select Amazon RDS, and create a new database instance. Choose MySQL as the engine.
Instance Settings: Define your instance details, including DB credentials, storage, and network configurations.
Connecting EC2 to RDS:
Go to your RDS database. Scroll to the "Connected compute resources" section and add your ec2 instance.
In your EC2 instance, run the following commands:
# Install mysql client sudo apt update sudo apt install mysql-client # Connecting your ec2 instance to the rds database. mysql -u admin -h <endpoint> -P 3306 -p
MySQL console will open. In the MySQL console, run the following:
create database aws; CREATE TABLE messages ( id INT AUTO_INCREMENT PRIMARY KEY, message TEXT );
Deployment: Bringing Your Application to Life
Running the docker container: Run the docker container we created before with MySQL environment variables as below
sudo docker run -d -p 5000:5000 -e MYSQL_HOST=<endpoint> -e MYSQL_USER=admin -e MYSQL_PASSWORD=admin123 -e MYSQL_DB=aws two-tier
Testing the Full Setup: Validate your two-tier application in the browser, by going on the URL
http://<ec2-public-ip>:5000
.
Conclusion
Congratulations on successfully deploying a two-tier application on AWS! Today's journey has taken you through the intricacies of Docker, Amazon RDS, and the orchestration of cloud resources.
Stay tuned for Day 5, where we'll explore advanced AWS services, propelling your cloud expertise even further!
Follow me on LinkedIn.
Checkout my GitHub profile.