4.18 Launch Configurations & Auto Scaling Groups
Steps:
Create a health check html page. Upload it to the S3 bucket of the last lab where also contains your index.html file.
Remember we also have created a ELB before, we will use it in this lab.
Before you create a Auto Scaling Group, you need to go to create Launch Configuration firstly.
Create Launch Configuration (similar to create an instance)
Choose an AMI and choose instance type.
Configure details. Add "AmazonS3FullAccess" role to this instance. Add your bootstrap bash script in the user data text area in Advanced Details. (Slightly changing one sentence: "aws s3 cp s3://[your-s3-bucket-name] /var/www/html/ --recursive", coping the whole directory because now you not only have index.html, you also have healthcheck.html, and copy should be recursively)
Configure security group and review and launch your Launch Configuration. Then you will be redirected to Create Auto Scaling Group.
Create Auto Scaling Group
The Launch Configuration is created just now and you cannot change it.
You can set the Group Size, Network and Subnet. For the Subnet, if you set the group size to be 3 (start with 3 instances), there will be 3 AZs can be chosen as the subnet. You'd better choose all these 3 AZs to be the subnet so that the AWS will put your 3 instances in different AZs, so that if one or two AZs crashed, your website will not have any downtime.
Advanced Details. This part is important. You can click "receive traffic from one or more ELB" and select the ELB you have created in the ELB lab. Select the Health Check Type to be ELB (Note: you can select EC2 or ELB. If we have not an ELB, we usually choose EC2, and that will use the results of the EC2 itself status checks to determine the health status of the instances. If we have an ELB associated with this auto-scaling group, we usually choose ELB, and that will use both of HTTP checking healthcheck.html and the EC2 status checks to determine the health status of the instances). You can also set a health check grace period, this period of time will be left for bootstrapping your instances (executing the bootstrap bash script). If you are using application load balancer, select a target group; if you are using a classic load balancer, select a classic load balancer.
Configure scaling policies. This allows you to automatically increase/decrease the number of instances in your auto scaling group based on these scaling policies. These policies are a set of CloudWatch metric thresholds and you can use CloudWatch alarms to determine when your Auto-scaling group should scale out or scale in.
Configure notifications. You can send notifications to recipients through their email addresses. (based on CloudWatch alarm and using SNS).
Configure your tags.
Review and create your Auto Scaling Group.
Go to EC2 Instances, you will see there are 3 instances are launching and they are spread across 3 AZs. When they are all launched, you can visit the webpage index.html through their public IP address.
Go to ELB, you can also visit the webpage index.html through the DNS name of this ELB.
You can terminate two of the instances to simulate there are two AZs are crashed. You still can visit your website through ELB or through the public IP address of the alive instance. ELB now will only send traffic with the alive instance. Now, the Auto Scaling Group will scale your group automatically based on your scaling policies, for example, there may be another new instance is starting in another AZ.
You can delete your auto scaling group through going to Auto Scaling Group and click Action -> Delete. This will shutting down the instances in this group as well.
Last updated
Was this helpful?