Scaling in AWS
- Vertical Scaling:
- Increasing resources to the EC2 instance i.e. changing the instance type
- To achieve this we need to stop the ec2 instance and then resize
- Horizontal Scaling:
- Increasing the EC2 instance which run the same application so that the load can be distributed.
Lab Setup
- To understand Horizontal Scaling and Elasticity lets create two AMIs
- LAMP Stack on ubuntu:
- Create a t2 micro ubuntu 18.04 ec2 instance
sudo apt update sudo apt install apache2 -y sudo apt install php libapache2-mod-php php-mysql php-cli -y # Create a file at /var/www/html/info.php with below content <?php phpinfo(); ?> sudo apt install stress -y
- Create AMI for this instance
- Spring pet clinic on ubuntu
- Steps for manual installation
1 sudo apt update 2 sudo apt install openjdk-11-jdk -y 3 sudo mkdir /usr/share/springpetclinic 4 wget https://referenceapplicationskhaja.s3-us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar 5 sudo cp spring-petclinic-2.4.2.jar /usr/share/springpetclinic/ 6 sudo adduser springbootuser 7 sudo chown springbootuser:springbootuser /usr/share/springpetclinic/spring-petclinic-2.4.2.jar 8 sudo chmod 500 /usr/share/springpetclinic/spring-petclinic-2.4.2.jar 9 sudo vi /etc/systemd/system/springpetclinic.service 10 sudo systemctl enable springpetclinic.service 11 sudo systemctl start springpetclinic.service 12 sudo systemctl status springpetclinic.service 13 sudo apt install stress -y
- Create an AMI from this ec2 instance
- LAMP Stack on ubuntu:
- When we run the AMI in an ec2 instance, users will access the application by giving public IP address
- In Reality we might be using domain names. (skip domain names)
- The application is run on webserver
- In AWS we have elastic load balancer which can distribute load across multiple ec2 instances and we have auto scaling group which can create multiple ec2 instances
- depending on the static count
- Scale out and scale in (increase or decrease the number of ec2 instances) based on ec2 metrics like CPU, network I/O
- To Create an autoscaling group, we need to have an AMI with application preinstalled or we can install after launch
- Lets explore autoscaling groups
- Auto Scaling groups requires one of the below
- Launch Template
- Launch Configuration
- In Launch Template/Launch Configuration we specify the details about
- AMI to be used
- Network in which ec2 instance has to be created
- key pairs
- security groups
- instance types
- Then in Auto scaling group we specify
- Conditions when the number of ec2 instances should increase or decrease
- To Effectively work with autoscaling groups we will associate
- Elastic Load balancer
- Application Load Balancer
- Network Load Balancer
- For our lab purposes, to generate artificial load on the ec2 instances we will be stress tool.