This project demonstrates the deployment of a web application with autoscaling on AWS and load testing using Locust. The application predicts the graduation status of students based on their grades.
- Project Overview
- Prerequisites
- Setting Up AWS Infrastructure
- Setting Up Load Balancer
- Deploying Locust for Load Testing
- Locust Configuration
- Monitoring and Autoscaling
- Contributing
- License
This project aims to demonstrate the implementation of autoscaling to improve the efficiency and performance of a web application during user traffic spikes. The web application is built using Streamlit and predicts student graduation status based on their grades. Locust is used for load testing.
- AWS Account
- SSH Key Pair for EC2
- Basic knowledge of AWS services
- Python and pip installed on your local machine
-
Launch an EC2 instance:
- AMI: Amazon Linux 2
- Instance type: t2.micro (Free Tier eligible)
- Key pair: Select an existing key pair or create a new one
- Security group: Create a new security group with the following rules:
- SSH (port 22)
- HTTP (port 80)
- Custom TCP (port 8501 for Streamlit)
- Custom TCP (port 8089 for Locust)
-
Connect to your EC2 instance:
ssh -i "path/to/your-key-pair.pem" ec2-user@your-ec2-public-dns
sudo yum update -y
sudo yum install python3 git -y
sudo python3 -m ensurepip
sudo pip3 install --upgrade pip
sudo pip3 install virtualenv
git clone https://github.com/Yoga-Syahputra/graduation-prediction-system.git
cd graduation-prediction-system
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
nohup streamlit run app.py --server.port 8501 --server.headless true &
Access the application at http://your-ec2-public-dns:8501
- Go to the EC2 Dashboard.
- Under Load Balancing, select Target Groups.
- Click on Create target group.
- Select Instances as the target type.
- Configure the target group:
- Name:
uat-target-group
- Protocol: HTTP
- Port: 8501
- VPC: Select your VPC
- Name:
- Click Create.
- Go to the EC2 Dashboard.
- Under Load Balancing, select Load Balancers.
- Click on Create Load Balancer and select Application Load Balancer.
- Configure the load balancer:
- Name:
uat-load-balancer
- Scheme: Internet-facing
- Listeners: HTTP (port 80)
- Availability Zones: Select the same VPC and at least two subnets
- Name:
- Click Next: Configure Security Settings.
- Click Next: Configure Security Groups, and select your security group.
- Click Next: Configure Routing.
- Configure the target group:
- Target group:
uat-target-group
- Protocol: HTTP
- Port: 8501
- Target group:
- Click Next: Register Targets, and add your EC2 instance.
- Click Next: Review, and then Create.
- Go to the EC2 Dashboard.
- Under Network & Security, select Security Groups.
- Select the security group associated with your EC2 instance.
- Add the following inbound rules:
- Type: HTTP, Protocol: TCP, Port range: 80, Source: 0.0.0.0/0
- Type: Custom TCP, Protocol: TCP, Port range: 8501, Source: 0.0.0.0/0
- Type: Custom TCP, Protocol: TCP, Port range: 8089, Source: 0.0.0.0/0
-
Install Locust:
pip install locust
nohup locust -f locustfile.py --host http://your-load-balancer-url --web-host 0.0.0.0 &
Access Locust interface:
- URL:
http://your-ec2-public-dns:8089
- Configure the number of users and spawn rate, then start the test.
Configure number of users and spawn rate:
- Number of users: [adjustable]
- Spawn rate: [insert the number here] user per second
- Host:
http://<load-balancer-url>
- Monitor your application performance using the AWS Management Console.
- Set up CloudWatch Alarms to trigger scaling actions based on metrics like CPU utilization.
- Configure Autoscaling Groups to automatically add or remove instances based on demand.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.