Amazon EC2 Auto Scaling helps you ensure that you have the right number of instances The right Amazon EC2 is available to handle the load for your application. You make collection of EC2 instances, called Auto Scaling Groups. You can specify a minimum amount instances in each Auto Scaling group, and Amazon EC2 Auto Scaling ensures that your groups never goes below this size. You can specify the maximum number of instances in each Auto Scaling group, and Amazon EC2 Auto Scaling ensures your groups are never in above this size. If you specify the desired capacity, fine when you create the group or any time afterward, Amazon EC2 Auto Scaling ensures your group has plenty of this instance. If you specify a scaling policy, then Amazon EC2 Auto Scaling can launch or stop instances when demand on your application increases or decrease.
You can create EC2 auto-scaling groups, a collection of EC2 instances. Set a minimum scaling value so that the group is never smaller than the specified size (if an instance fails, it is replaced). Set a maximum number of EC2 instances and the group will not exceed the specified size.
In addition, you can:
Manually add or remove EC2 instances from auto scaling groups (this is called manual scaling)
Change minimum or maximum capacity of a group on a predefined schedule
Set scaling plans that dynamically scale groups up and down
Configuration AWS
Create new Security Group
Name :SG-For-ASGInbound Rules :-SSH| from Anywhere (IPv4)-HTTP| from Anywhere (IPv4)-HTTPS| from Anywhere (IPv4)Outbound Rules :- All Trafic | from Anywhere (IPv4)
Create Target Groups
In the left menu panel select Target Group and click "Create target groups"- Choose a target type: Instances- TG name : myTG- Health check path :/- Advance health check settings* Healthy threshold :2* Unhealthy threshold :2* Timeout :2* Interval :5click Nextwithout selecting any instance, immediately click "Create target group"
Create Load Balancer
IntheleftmenupanelselectLoadBalancersthenclick"Create load balancer"-Choose"Application Load Balancer"-setname:ELB-for-Autoscaling-NeworkMapping:CheckallAvailabilityZones.-Securitygroups:selectSG-for-ASG-Listenersandrouting* protocol : HTTP* port : 80* Default action : Forward to myTG -> Select the target group that has been created.clickCreatetargetgroup.
Create Launch Template
IntheleftmenupanelselectLaunchTemplates,thenclick"Create launch template"-launchtemplatename:LT-for-ASGdescription:WebserverforAutoScaling.Autoscalingguidance:check-AMI/OS:Ubuntu22.04LTS-Instancetype:t2.micro-Keypair:vockey-Networksettings:*select existing security group = SG-for-ASG-Resourcetags,addednewkey=Namevalue=EC2-ASG-<your-name>Resourcetype=Instance-Advanceddetails* scroll down, to the User Data sectionaddthefollowingscript:#!/bin/bashsudoaptupdatesudoaptinstallapache2wgetunzipphp-ysudowgethttps://us-west-2-tcprod.s3.amazonaws.com/courses/ILT-TF-100-TECESS/v4.7.2/lab-1-build-a-web-server/scripts/lab-app.zipsudounziplab-app.zip-d/var/www/html/sudorm-f/var/www/html/index.htmlClickcreatelaunchinstance.
Create Auto Scaling Group
IntheleftmenupanelselectAutoScalingGroups,thenclickcreate.-Name:myASG-Launchtemplate:LT-for-ASGclickNext-VPC:Default-AvailabilityZonesandSubnets:selectorCHECKALLsubnetsclickNext-Loadbalancing:Attachtoanexistingloadbalancer-Selecttargetgroup:myTG-Healthchecks:Check'Turn on ELB health checks'-Additionalsettings:Check'Enable group metrics collection...'clickNext-Groupsize* Desired capacity: 1* Minimum capacity: 1* Maximum capacity: 3-Scalingpolicies:click'Target tracking scaling policy'* Target value: 10* Instance need : 5 secondsClickNexttogototheReviewpageclickcreateAutoScalingGroup
Configuration is Completed
Trials :
Go to the Instances menu, make sure there is 1 EC2 instance created automatically.
wait until the status is running and 2/2 checks passed, (-+ 5 minutes)
Access the web via Elastic Load Balancer DNS
Run Load Test
Check again in the instances menu, now 2 new instances have been added (scale up).