DEV Community

Arjun Menon
Arjun Menon

Posted on • Originally published at arjunmenon.hashnode.dev on

Deploying a Two-Tier Web App with MySQL on Amazon RDS

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

  1. Installation: Begin by installing Docker on your EC2 instance. This will be the backbone of your containerized web app.

  2. Cloning the Repository: Clone this repository which contains the Dockerfile.

  3. 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:

  1. Database Instance Creation: Navigate to the AWS Management Console, select Amazon RDS, and create a new database instance. Choose MySQL as the engine.

  2. Instance Settings: Define your instance details, including DB credentials, storage, and network configurations.

Connecting EC2 to RDS:

  1. Go to your RDS database. Scroll to the "Connected compute resources" section and add your ec2 instance.

  2. In your EC2 instance, run the following commands:

4.

 # 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

Enter fullscreen mode Exit fullscreen mode
  1. MySQL console will open. In the MySQL console, run the following:

6.

 create database aws;
 CREATE TABLE messages (
     id INT AUTO_INCREMENT PRIMARY KEY,
     message TEXT
 );

Enter fullscreen mode Exit fullscreen mode

Deployment: Bringing Your Application to Life

  1. Running the docker container: Run the docker container we created before with MySQL environment variables as below

2.

 sudo docker run -d -p 5000:5000 -e MYSQL_HOST=mysql -e MYSQL_USER=admin -e MYSQL_PASSWORD=admin123 -e MYSQL_DB=aws two-tier

Enter fullscreen mode Exit fullscreen mode
  1. 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.

Top comments (0)