Creating an Auto Scaling group

After the launch configuration is created you are directly taken to the creation of Auto Scaling groups:

  1. The first step is to specify the auto scaling group details:
    • Launch Configuration: The launch configuration for this auto scaling group. This is pre-filled in our case as A1EcommerceLaunchConfig.
    • Group name: The name of the group for this Auto Scaling group.
    • Group size: The size here refers to the minimum number of instances that run inside the auto scaling group. This number typically depends on the load the application is expecting and how many requests a single instance can serve without any latencies. Since ours is a demo with the aim to keep the costs to a bare minimum, we start with one instance.
    • Network: Select the VPC where the auto scaling group will launch. Use the default VPC already created in Chapter 3.
    • Subnet: Select the default subnet for the Auto Scaling group within the selected VPC. 

Click on the Advanced Details link to expand it:

  • Load Balancing: An Auto Scaling group can be associated with an elastic load balancer. Select the elastic load balancer we created earlier in this chapter in the Creating Elastic Load Balancer section, a1electronicsecommerce-elb. If you are using other means of load balancing for your Auto Scaling group then uncheck this option. 
  • Health Check Type: The Auto Scaling group performs health checks on the instances in the group and replaces the failed instances with new ones. It can either use the results of the elastic load balancer or monitor the state of the EC2 instance to detect a failed instance. Select the ELB option since we have configured our auto scaling group to use an ELB.
  • Health Check Grace Period: When an instance comes up it might take some time before it starts responding to the health checks. The time should always be greater than the expected boot time of the instance plus the startup time of the application. Choose the default value of 300 seconds. Now, click on the Next: Configure scaling policies button:
  1. Next we configure the scaling policies for the Auto Scaling group. A policy is a rule which defines how to scale in our response to varying conditions. The two options are:
    • Keep this group at its initial size: This is a static option. The auto scaling group does not scale in or out the number of instances specified for group size (as defined earlier). The Auto Scaling group will monitor and replace any failed instances.
    • Use scaling policies to adjust the capacity of this group: This option allows the auto scaling group to scale in or out dynamically depending the conditions. These conditions are alarms set in CloudWatch which monitor a pre-selected metric of an AWS resource. Whenever an alarm goes off, breaching the metric limit, CloudWatch sends a message to the scale-in or the scale-out policy which in turn invokes the scaling activity. There are two policies to be defined, one for scaling in and the other for scaling out.

Set the minimum and maximum instance in the Auto Scaling group. This depends on your application and the server's instance type. For our purpose, set this minimum to 1 and maximum 2. Next, we define the policy which will increase the number of instance in an Auto Scaling group when an alarm associated with it goes off. Now, click on the Scale the Auto Scaling group using step or simple scaling policies link:

  1. You should see the following screen:
    • Name: Name of the increase group. Keep the default value.
    • Execute policy when: This is where we create an alarm which will be triggered by CloudWatch when it is breached. Since there are no alarms set, click on Add new alarm. See step 5 for more details. 
    • Take the action: When the alarm triggers, we can either add or remove an instance in terms of either percentage of total instances or by a fixed number of instances. Since it is a scale-out situation, we add an instance to the auto scaling group. Adding instances can be done either in terms of percentage of the total machines running in the auto scaling group or by a fixed number of instances. Since the maximum instances in our auto scaling group is two, increasing by a percentage does not make sense.

Now, click on the Add new alarm link:

  1. You should see the following screen. Now, click on the create topic hyperlink:
  1. Your should see the following screen. Fill in the details for the topic name and enter an email address in the recipients field. 

When creating a CloudWatch alarm for scaling out, it is very important to choose the right set of parameter values for the pre-conditions (of the scale-out). The idea is to trigger the alarm 5 to 10 minutes before the 75% of the target threshold is reached. You need to take into account the bootup time of the instance as well as whether the application before the instance is ready to serve the requests; hence we trigger early and catch up with the future demand. The metric we are using to trigger the alarm is CPU utilization. The other useful metrics which can be used are network utilization and memory utilization. The alarm we want to set is trigger the alarm when the CPU utilization of the EC2 instance is greater than 60% for at least 5 minutesThe fully filled out screen details are displayed as follows. Now, click on the Create Alarm button:

You should see the following screen:

  1. Next, we will configure the policy for decreasing the group size. As done before, we create a separate topic for the scale in part. The filled out details are as shown. The alarm we want to set is trigger the alarm when the CPU utilization of the EC2 instance is less than 30% for at least 20 minutesClick on the Create Alarm button:
  1. You should see the following screen:
    • Decrease Group Size: Next, we define the policy which will decrease the instance in an auto scaling group when an alarm associated with it goes off.
    • Name: Name of the decrease group. Keep the default value.
    • Execute policy when: This is where we create an alarm which will be triggered by CloudWatch when it is breached. Since there are no alarms set, click on Add new alarm
    • Take the action: When the alarm triggers we can either add or remove an instance in terms of either the percentage of total instances or by a fixed number of instances. Since it is a scale-in situation, we remove an instance from the Auto Scaling group. Adding instances can be done either in terms of the percentage of total machines running in the Auto Scaling group or by a fixed number of instances. Since the minimum instances in our Auto Scaling group is one, decreasing it by a percentage does not make sense.

Change the number of instances to one for the Take the Action field for both the groups (Add one for Increase Group Size and Remove one for Decrease Group Size). Click on the Next: Configure Notification button:

  1. Next, we configure the Auto Scaling group to send the notifications to the Amazon SNS topic whenever a scaling event takes place. Currently, we are only interested in fail to launch and fail to terminate scaling events, but in production it is strongly recommended to send all the scaling events. Now, click on the Add notification button:
  1. You should see the following screen. For the Scale Out topic, select the options for launch and fail to launch, and for the Scale In topic select the terminate and fail to terminate options. Now, click on the Next: Configure Tags button:
  1. Next, we configure tags; these tags will be applied to all the instances managed by the Auto Scaling group. A maximum of 10 tags can be configured. This is useful when there are many auto scaling groups for different layers. It becomes easier to identify the EC2 instances in the dashboard. Make sure you to select the Tag New Instances option. Enter the Key field as Name and the Value field as A1EcommerceASG. Now, click on the Review button:
>
  1. The next step is to review and create the Auto Scaling group. From the navigation pane of the EC2 dashboard, click on Auto Scaling Groups; this will list all the auto scaling groups. When the Auto Scaling group is created it also creates the alarms in CloudWatch and topics in SNS. When the Auto Scaling group starts, it starts with the minimum number of instances. Now, click on the Create Auto Scaling group button:
  1. You should see the following message. Click on the Close button:
  1. At this stage, check your emails. You should see two emails: one for the Scale Out and the other for the Scale In topic. In the following screenshot, we show you the Scale In message only. Click on the Confirm subscription hyperlink:
  1. You should see the following screen confirming the subscription:

You have now completed the Auto Scaling group creation process. In the next section, we will test the Auto Scaling group to ensure it is functioning as expected.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.218