12K Views

Set up Amazon Auto Scaling

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.

Click in “Create Auto Scaling group” to begin.

First we need to create launch configuration, so click on “Create launch configuration” .

Then, it will ask you to select an AMI for launch configuration. We are using my custom AMI named as DND – ami-09e3a91f which has LAMP server and other dependencies already installed.

Here, we will select t2.micro instance that comes under AWS free-tier criteria. Moving further to configure details,

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.

Taking all values as defaults, we will move on to configure security group.

We will here select an existing security group that is listening to our ports or we can create a new security group and setup access control list in it.

Review launch configuration details. AWS will launch instances on the basis of this template. After reviewing, click on “Create launch configuration”.

Here, we are choosing an existing key pair. We can also create a new key pair. Clicking on Create launch configuration,

After a while, launch configuration will get created and we can review all details. Now we have to create Auto scaling group.

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:

As we can see, we have already created an alarm for scale-in policy based on CPU usage. Moving on to next step,

HereĀ  we will configure no notification policies and move to further step,

Add a tag to our group and click on review.

Review all the details and click on Create Auto Scaling group.

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.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php