AWS Zero to Hero Day 4 - part 2

Amitabh soniAmitabh soni
2 min read

Table of contents

Task 3: Deploy a scalable web application. The application consists of a MySQL database managed by Amazon RDS and a flask based web application that automatically scale based on demand using an Auto Scaling group and an Elastic Load Balancer.

Ans:

  1. Created AWS RDS with MySQL:

  2. Created EC2 template with following user data:

     #!/bin/bash
    
     # Update system
     sudo apt update -y
    
     # Install Docker & MySQL client
     sudo apt install docker.io mysql-client -y
    
     # Add 'ubuntu' user to Docker group
     sudo usermod -aG docker ubuntu
    
     # Enable Docker service
     sudo systemctl enable docker
     sudo systemctl start docker
    
     # Wait until the RDS instance is ready to accept connections (optional but useful)
     until mysql -u admin -h database-1.cdsswsgcuo0c.us-east-1.rds.amazonaws.com -P 3306 -pdevops2004 -e "SELECT 1;" &>/dev/null; do
       echo "Waiting for MySQL..."
       sleep 5
     done
    
     # Create the database if it doesn't exist
     mysql -u admin -h database-1.cdsswsgcuo0c.us-east-1.rds.amazonaws.com -P 3306 -pdevops2004 -e "CREATE DATABASE IF NOT EXISTS flaskdb;"
    
     # Pull your Flask app Docker image
     sudo docker pull amitabhdevops/aws-flask-app:latest
    
     # Run the Flask app
     sudo docker run -d \
       --name flaskapp \
       -e MYSQL_HOST=database-1.cdsswsgcuo0c.us-east-1.rds.amazonaws.com \
       -e MYSQL_USER=admin \
       -e MYSQL_PASSWORD=devops2004 \
       -e MYSQL_DB=flaskdb \
       -p 80:5000 \
       amitabhdevops/aws-flask-app:latest
    
  3. Then, Created AWS AutoScaling Group with this template

  4. After that, I created an IAM role for EC2 service with RDS and CloudWatch full access, and attached it to my EC2 Instance

  5. Modified the RDS to connect with my Instance

  6. Connected to first instance, which is created from ASG

  7. and checked the databases content

  8. output images:

0
Subscribe to my newsletter

Read articles from Amitabh soni directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Amitabh soni
Amitabh soni

DevOps Enthusiast | Passionate Learner in Tech | BSc IT Student I’m a second-year BSc IT student with a deep love for technology and an ambitious goal: to become a DevOps expert. Currently diving into the world of automation, cloud services, and version control, I’m excited to learn and grow in this dynamic field. As I expand my knowledge, I’m eager to connect with like-minded professionals and explore opportunities to apply what I’m learning in real-world projects. Let’s connect and see how we can innovate together!