In our previous blog, we got an overview about aws auto scaling, its features and its applicability. In this blog, we will begin with setting up an Auto Scaling Group and integrating it with AWS Elastic Load Balancer and AWS CloudWatch.
Getting Started With Launch Configuration
First and foremost, we will create a launch configuration which acts as a template that Auto scaling group uses to launch EC2 instances. It contains information about AMI ID, instance type, one or more security groups, subnet(s), key-pair, user data etc. But before that, login to your AWS account and go to https://console.aws.amazon.com/ec2/ and go to Launch Configurations under Auto Scaling Category.
Here, we have named our launch configuration as “new-launch-configuration”. As shown above, we are taking all the other values as default. Although we have mentioned simple bash script in user data. User data contains set of commands that we want to get executed on the instances launched by auto scaling group. At this point, we are just entering a digit in a file as an example. Now, moving on to adding storage.
Getting Started with Auto Scaling Group
We have named our auto scaling group as “new-autoscaling-group”. Group size is set on 1 which defines nuber of instances gets launched after the auto scaling group creation. Also, we have selected our default VPC and all subnets within that region. On further scrolling down, configure advanced details as:
We have checked on option for receiving traffic from load balancer and also selected our already created classic load balancer naming “test”. To create a classic load balancer, go to http://cloudkul.com/blog/how-to-create-a-classic-load-balancer. We will take rest of the values as default and move on to configure scaling policies.
As auto scaling group automatically scales instances up and down, depending upon the policies created, we will choose scaling policies to adjust capacity of this group. Policies can be created with the help of Amazon CloudWatch. Here, we have already created an alarm for scale out policy depending upon CPU usage. For more info regarding how to create CPU usage alarm. go to http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_AlarmAtThresholdEC2.html. Now, moving on to create scale in policy:
Now, our auto scaling group has been created which receive traffic from load balancer naming “test” and, has desired number of instances as 1 and minimum to maximum instance counts as 1 to 2. As we have no running instance associated with our load balancer under this auto scaling group, a new instance will be launched using launch configuration to satisfy the minimum instance count setting of our auto scaling group. After passing through load balancer health checks, a new instance will be created under this group.
As we can see, an instance is InService within one the availability zone of our region using our custom launch configuration. Although, we have already created our scaling policies, but we can add more alarm based on these policies by clicking on “Scaling Policies” option. Click on add policy and create a new alarm as:
This is the same alarm that we have created for monitoring CPU usage for scale out policies.
Our AWS Auto Scaling Group is all setup with integration with AWS Classic Load Balancer and AWS CloudWatch. We can create more scaling policies for auto scaling group to ensure high availability and reduce server downtime.
So far we have discussed about creating amazon auto scaling group. In our next blog, we will discuss a complete architecture using AWS resources.