Owing to the very simple yet powerful features, Amazon has truly been the most dominating player in the world of cloud and one of the most undisputed super heroes of the cloud market. Out of the many amazing features of Amazon, this blog intends to highlight the auto scaling feature of EC2 instances.
The scaling power that cloud offers us is really powerful; one that requires minimal effort to give optimal resource utilization. Amazon takes a step ahead by further automating the process of scaling up and down your servers on the fly. Achieving optimal use of resources by shutting down the servers with minimal traffic and scaling up in spike time has helped many companies to save thousands of dollars. This blog will explain in a few easy steps how this can be achieved.
The entire autoscaling activity can be explained in four easy steps on the Amazon CLI interface.
Four Easy Steps to Autoscale instances
Specify the template that Auto Scaling uses to launch Amazon EC2 instances.
as-create-launch-config my-launch-config --image-id ami-xxxxx --instance-type m1.small --group my-sg-groupname--region region-name--I yourAccesskey --S yourSecretKey
my-launch-config: specify a unique template name ami-xxxxx: Specify the AMI id of the server that you want to spin up m1.small: specify the type of instance/size for spine up my-sg-groupname: specify the security group name to be applied to a new spin up instance
After creating the template it is necessary to specify where and how the scaling is to be performed.
as-create-auto-scaling-group my-autoscaling-grp--launch-configuration my-launch-config--availability-zones us-west-1a,us-east-1a--min-size 1 --max-size 10 --desired-capacity2--load-balancers LoadbalancerName --region region-name--I yourAccesskey --S yourSecretKey
us-west-1a: Specify the zone in which the new instance is to spin. It is always recommended to specify two different availability-zones as a safe practice/disaster recovery.
--min-size/--max-size: the minimum number/maximum of instances in your autoscaling group --desired-capacity: specify the number of instances on startup to be launched
The third step describes the policy to scale up and scale down.
as-put-scaling-policy--auto-scaling-group my-scaleup-policy --name scale-up "--adjustment=1" --type ChangeInCapacity --cooldown 300 --region region-name--I yourAccesskey --S yourSecretKey
--adjustment=1: to add 1 new instance to the autoscaling group --adjustment=-1: to decrease 1 instance from the autoscaling group --cooldown 300: specify the time lag between the successive triggers of the same policy.
ReturnMessage:arn:aws:autoscaling:us-west-1:751374139099:scalingPolicy:xxxxxxxx-xxxxx-xxxx-xxxx:autoScalingGroupName/sg-securitygroup-gma:policyName/scale-up
The last step in autoscaling is to specify the condition when the scaling policy is to be triggered which is set using the cloud watch alarms.
After specifying the condition when the alarm should be triggered (here CPU 50%), select the action and the autoscaling group in the relevant combos. The instance is then ready to autoscale.