{"id":11230,"date":"2013-12-17T15:42:42","date_gmt":"2013-12-17T10:12:42","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11230"},"modified":"2015-07-31T15:57:37","modified_gmt":"2015-07-31T10:27:37","slug":"beginners-guide-to-aws-auto-scaling","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/beginners-guide-to-aws-auto-scaling\/","title":{"rendered":"Beginner&#8217;s guide to AWS auto-scaling"},"content":{"rendered":"<p>Recently, we\u2019re about to launch a new app but we did not have any idea about the traffic we\u2019ll get. It could have been in hundreds or even thousands. So, we decided to go for Amazon\u2019s Auto Scaling feature. Auto Scaling is the appropriate solution for your app when you are not certain about your app\u2019s traffic or in cases where the traffic is really high or expected to go high during a certain period of time; be it for an hour, a day or a week.<\/p>\n<p>Before we discuss on how to setup auto scaling, we will discuss a bit about what is auto scaling and how it can help you tackle those unknown and uncertain traffic scenarios.<\/p>\n<p><strong>What is auto scaling?<\/strong><\/p>\n<p>It is a service provided by Amazon Web Services which allows you to scale up or down your infrastructure horizontally by automatically adding or removing EC2 instances based on user-defined policies, health status checks or schedule.<\/p>\n<p>Auto-scaling allows you to scale your computed resources dynamically or predictably:<\/p>\n<ul>\n<li>In Dynamic scaling you can start and stop ec2 instances based on different pre-defined conditions.<\/li>\n<li>In Predictable scaling you are certain about traffic patterns such as cases where traffic peaks every morning and goes down in the afternoon; you can have auto scaling start more Web servers in the morning and shutdown unnecessary ones in afternoon.<\/li>\n<\/ul>\n<p>Following are the steps which can be followed to setup auto scaling:<\/p>\n<p><strong>Prerequisite for setting up an auto scaling<\/strong><\/p>\n<ol>\n<li><strong>AMI (Amazon Machine Image):<\/strong>\u00a0\u00a0In the beginning you set up only one instance in which you install all the required applications, necessary for your Website. After that, copy it to an AMI and use that image for launching more instances.But there are few drawbacks in this method which you need to keep in mind, such as: an image may become out of date during the period of time and the difficulty of keeping track of many types of images for different purposes.There are more flexible ways to tackle these, as you can fire up simple ec2 instance and configure it on the fly where time of booting for this one can use any of the configuration management tools like Puppet\/Chef.<\/li>\n<li><strong>Auto Scaling command line tool :<\/strong>In order to install the Auto Scaling Command line one can follow the instruction mentioned here: \u00a0\u00a0http:\/\/docs.aws.amazon.com\/AutoScaling\/latest\/DeveloperGuide\/UsingTheCommandLineTools.html<strong><br \/>\n<\/strong><strong><br \/>\n<\/strong><\/li>\n<li><strong>Cloud Watch Monitoring Tool:<\/strong>You can define \u2018cloud watch monitoring\u2019 alert to trigger auto scaling policy. To install Cloud Watch CLI tools follow the instruction here: \u00a0http:\/\/docs.aws.amazon.com\/AmazonCloudWatch\/latest\/DeveloperGuide\/SetupCLI.html<strong><a href=\"http:\/\/docs.aws.amazon.com\/AmazonCloudWatch\/latest\/DeveloperGuide\/SetupCLI.html\" target=\"_blank\"><br \/>\n<\/a><\/strong><strong><br \/>\n<\/strong><\/li>\n<li><strong>Elastic Load Balancer:<\/strong>\u00a0Whenever demand fluctuates, auto scaling\u00a0dynamically adds and removes EC2 instances from the load balancer. So to insure that the traffic is distributed across all the running EC2 instances, you can use Load Balancer.\u00a0It automatically distributes incoming Web traffic to multiple EC2 instances.<\/li>\n<\/ol>\n<p><strong>Configuring auto scaling<\/strong>:<br \/>\nIt consists of four simple steps:<\/p>\n<ol>\n<li><strong>Launch Configuration: &#8211;<\/strong>\u00a0In launch config, you specify the template that auto scaling uses to launch EC2 instances. \u00a0In the below mentioned command you define the launch config name, AMI, instance type and the security group for the EC2 instances.\n<p>[shell]<br \/>\nas-create-launch-config\u00a0ig-aslc\u00a0&#8211;image-id\u00a0ami-b69e37e4\u00a0&#8211;instance-type\u00a0m1.small\u00a0&#8211;group\u00a0testingAS<br \/>\n[\/shell]<\/p>\n<p><strong><br \/>\n<\/strong><\/li>\n<li><strong>Auto Scaling Group : <\/strong>Auto Scaling Group is the core part of auto scaling service. Here, you can define settings like minimum, maximum and desired number of EC2 instances for an auto scaling group.\n<p>[shell]<br \/>\nas-create-auto-scaling-group\u00a0ig-asg\u00a0&#8211;launch-configuration\u00a0ig-aslc\u00a0&#8211;availability-zones\u00a0&quot;ap-southeast-1a&quot;,&quot;ap-southeast-1b&quot;\u00a0&#8211;load-balancers\u00a0igASelb\u00a0&#8211;health-check-type ELB &#8211;grace-period 300 &#8211;max-size\u00a06\u00a0&#8211;min-size\u00a02\u00a0&#8211;desired-capacity\u00a02<br \/>\n[\/shell]<\/p>\n<p>Now based on\u00a0<strong>ig-asg<\/strong>\u00a0group and\u00a0<strong>ig-aslc,<\/strong>\u00a0launch configuration auto scaling will launch\u00a0<strong>two EC2 instances<\/strong>\u00a0in two different availability zones: ap-southeast-1a and ap-southeast-1b respectively. And both the instances will be behind the\u00a0<strong>igASelb<\/strong>\u00a0Elastic Load balancer.<br \/>\n<strong><br \/>\n<\/strong><\/li>\n<li><strong>Auto Scaling Policy:\u00a0<\/strong>Auto scaling group takes action as per the auto scaling policy.<br \/>\nSo now you will create two auto scaling policies:<strong>ig-scaling-out\u00a0<\/strong>will increase the capacity of the\u00a0<strong>ig-asg<\/strong>\u00a0group and\u00a0<strong>ig-scaling-in\u00a0<\/strong>which decrease the capacity of\u00a0<strong>ig-asg<\/strong>\u00a0group.<br \/>\n1) Scaling Out Policy :<\/p>\n<p>[shell]<br \/>\nas-put-scaling-policy\u00a0ig-scaling-out\u00a0&#8211;auto-scaling-group\u00a0ig-asg\u00a0&#8211;adjustment=2\u00a0&#8211;type ChangeInCapacity &#8211;cooldown\u00a0300<br \/>\n[\/shell]<\/p>\n<p><em><strong><br \/>\n<\/strong><\/em>When you execute the above command it will returns the ARN that serves as a unique name for new policy.<\/p>\n<p>[shell]<br \/>\narn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName\/ig-asg:policyName\/ig-scale-out<br \/>\n[\/shell]<\/p>\n<p>Now you\u2019ll save this ARN at safe place as it\u2019ll be required when you configure monitoring.2) Scaling Down Policy :<\/p>\n<p>[shell]<br \/>\nas-put-scaling-policy\u00a0ig-scaling-in\u00a0&#8211;auto-scaling-group\u00a0ig-asg\u00a0&#8211;adjustment=-2\u00a0&#8211;type ChangeInCapacity &#8211;cooldown\u00a0300<br \/>\n[\/shell]<\/p>\n<p>Above command will return the ARN, You will save this too.<\/p>\n<p>[shell]<br \/>\narn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName\/ig-asg:policyName\/ig-scale-in<br \/>\n[\/shell]<\/p>\n<p>Cool\u00a0 Down period in auto scaling policy takes care of scaling activities (instance launch or instance terminate).<\/p>\n<p>As per mentioned command, you are using 300 seconds cool down period.<br \/>\nLet\u2019s say our auto scaling up policy has launched two new instances so it won&#8217;t terminate the server immediately. It will wait for 300 sec and then terminate the instances.<\/li>\n<li><strong>Monitoring Alarms :-\u00a0<\/strong>Now add a Cloud Watch monitor so if CPU load is more than 70% for more than 5 minutes, it will execute scaling out policy and whenever load goes down it will execute scale down policy.<br \/>\nBelow are the two commands which will do the same:<\/p>\n<p>[shell]<br \/>\nmon-put-metric-alarm &#8211;alarm-name\u00a0sample-scale-up\u00a0&#8211;alarm-description &quot;Scale Up at\u00a070%&quot; &#8211;metric-name\u00a0CPUUtilization\u00a0&#8211;namespace AWS\/EC2 &#8211;statistic Average &#8211;period\u00a060\u00a0&#8211;threshold5\u00a0&#8211;comparison-operator GreaterThanThreshold &#8211;evaluation-periods\u00a05\u00a0&#8211;unit\u00a0Percent &#8211;alarm-actions arn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName\/ig-asg:policyName\/ig-scale-out.[\/shell]<\/p>\n<p>[shell]mon-put-metric-alarm &#8211;alarm-name\u00a0sample-scale-dn\u00a0&#8211;alarm-description &quot;Scale down at55%\u00a0load&quot; &#8211;metric-name\u00a0CPUUtilization\u00a0&#8211;namespace AWS\/EC2 &#8211;statistic Average &#8211;period60\u00a0&#8211;threshold\u00a05\u00a0&#8211;comparison-operator LessThanThreshold &#8211;evaluation-periods\u00a05\u00a0&#8211;unit Percent &#8211;alarm-actions arn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName\/ig-asg:policyName\/ig-scale-in[\/shell]<\/p>\n<p>That&#8217;s it! You can find more information about auto scaling <a href=\"http:\/\/docs.aws.amazon.com\/AutoScaling\/latest\/DeveloperGuide\/WhatIsAutoScaling.html\" target=\"_blank\">here<\/a>.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Recently, we\u2019re about to launch a new app but we did not have any idea about the traffic we\u2019ll get. It could have been in hundreds or even thousands. So, we decided to go for Amazon\u2019s Auto Scaling feature. Auto Scaling is the appropriate solution for your app when you are not certain about your [&hellip;]<\/p>\n","protected":false},"author":90,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":7},"categories":[1174],"tags":[1172,1258,248,1257],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11230"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11230"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11230\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}