4176. AWS-Auto Scaling Groups
AWS and Load Balancer


Build high availability applications with Auto Scaling Groups.

1. High Availability Architecture

Everything fails, you should always plan for failures.

  • Always Design for failure.
  • Use Multiple AZ’s and Multiple Regions where ever you can.
  • Know the difference between Multi-AZ and Read Replicas for RDS.
  • Know the difference between scaling out and scaling up.

2. Auto Scaling Groups

An Auto Scaling group contains a collection of Amazon EC2 instances that are treated as a logical grouping for the purposes of automatic scaling and management. An Auto Scaling group starts by launching enough instances to meet its desired capacity. It maintains this number of instances by performing periodic health checks on the instances in the group. The Auto Scaling group continues to maintain a fixed number of instances even if an instance becomes unhealthy. If an instance becomes unhealthy, the group terminates the unhealthy instance and launches another instance to replace it. image

3. Lab - Auto Scaling Groups

Create autoscaling group with 3 instances. Test the auto scaling feature by terminating two instances. The auto scaling group should detect this scenario with health check, and new two instances will be launched automatically.

3.1 Create Launch Configuration

Go to Services->EC2->Auto Scaling->Launch Configurations, Create launch configuration. image Set name, search ‘amzn2-ami-hvm’ for AMI and choose ‘t2.micro’ as instance type, which should be free tier. image Copy the following bootstrap scripts which will start a web server to host a static html file.

#!/bin/bash
yum update -y
yum install httpd -y
service httpd start
chkconfig httpd on
cd /var/www/html
echo "<html><h1>Welcome to the EC2 Fleet!</h1></html>" > index.html

Paste them into the user data box. image Leave the storage settings unchanged. image Select WebSG security group and the existing key pair, click “Create launch configuration”. image Launch configuration is created. image

3.2 Create Auto Scaling Group

Go to Services->EC2->Auto Scaling->Auto Scaling Groups, click “Create Auto Scaling Group”. image Set name and click “Switch to launch template”. image Select the launch configuration we created in the previous section, next. image Set VPC and select all available subnets, next. image Leave without any change, next. image Configure the scale group size, Desired Capacity = 3, Minimal Capacity = 2, Maximum Capacity = 6, next. image Skip the notification, next. image Set instance tag, next. image Review and click “Create auto scaling group”. image The AutoScaling group is created. Three instances are under this group. image Go to EC2 instance, we see all instances are up. image If you visit the public ip of any instance in web browser, we will see the page. image Now, select any two instances, terminate them. image In the Activity history of the Auto Scaling group, we can see it detected the termination and launched new instances automatically. image After a while, new instances are launched. The auto scaling group ensures that there are always three instances alive. image

4. References