cdocutils.nodes document q)q}q(U nametypesq}q(X!getting existing autoscale groupsqNXcreating a connectionqNXautoscale conceptsqNX-an introduction to boto's autoscale interfaceq NXcreating autoscaling groupsq NXscaling a group up or downq NX"a note about regions and endpointsq NX autoscale_tutq uUsubstitution_defsq}qUparse_messagesq]qUcurrent_sourceqNU decorationqNUautofootnote_startqKUnameidsq}q(hU!getting-existing-autoscale-groupsqhUcreating-a-connectionqhUautoscale-conceptsqh U-an-introduction-to-boto-s-autoscale-interfaceqh Ucreating-autoscaling-groupsqh Uscaling-a-group-up-or-downqh U"a-note-about-regions-and-endpointsqh U autoscale-tutquUchildrenq]q (cdocutils.nodes target q!)q"}q#(U rawsourceq$X.. _autoscale_tut:Uparentq%hUsourceq&XC/Users/kyleknap/Documents/GitHub/boto/docs/source/autoscale_tut.rstq'Utagnameq(Utargetq)U attributesq*}q+(Uidsq,]Ubackrefsq-]Udupnamesq.]Uclassesq/]Unamesq0]Urefidq1huUlineq2KUdocumentq3hh]ubcdocutils.nodes section q4)q5}q6(h$Uh%hh&h'Uexpect_referenced_by_nameq7}q8h h"sh(Usectionq9h*}q:(h.]h/]h-]h,]q;(hheh0]q<(h h euh2Kh3hUexpect_referenced_by_idq=}q>hh"sh]q?(cdocutils.nodes title q@)qA}qB(h$X-An Introduction to boto's Autoscale interfaceqCh%h5h&h'h(UtitleqDh*}qE(h.]h/]h-]h,]h0]uh2Kh3hh]qFcdocutils.nodes Text qGX-An Introduction to boto's Autoscale interfaceqHqI}qJ(h$hCh%hAubaubcdocutils.nodes paragraph qK)qL}qM(h$XThis tutorial focuses on the boto interface to the Autoscale service. This assumes you are familiar with boto's EC2 interface and concepts.qNh%h5h&h'h(U paragraphqOh*}qP(h.]h/]h-]h,]h0]uh2Kh3hh]qQhGXThis tutorial focuses on the boto interface to the Autoscale service. This assumes you are familiar with boto's EC2 interface and concepts.qRqS}qT(h$hNh%hLubaubh4)qU}qV(h$Uh%h5h&h'h(h9h*}qW(h.]h/]h-]h,]qXhah0]qYhauh2K h3hh]qZ(h@)q[}q\(h$XAutoscale Conceptsq]h%hUh&h'h(hDh*}q^(h.]h/]h-]h,]h0]uh2K h3hh]q_hGXAutoscale Conceptsq`qa}qb(h$h]h%h[ubaubhK)qc}qd(h$X>The AWS Autoscale service is comprised of three core concepts:qeh%hUh&h'h(hOh*}qf(h.]h/]h-]h,]h0]uh2K h3hh]qghGX>The AWS Autoscale service is comprised of three core concepts:qhqi}qj(h$heh%hcubaubcdocutils.nodes block_quote qk)ql}qm(h$Uh%hUh&Nh(U block_quoteqnh*}qo(h.]h/]h-]h,]h0]uh2Nh3hh]qpcdocutils.nodes enumerated_list qq)qr}qs(h$Uh*}qt(UsuffixquU.h,]h-]h.]UprefixqvUh/]h0]UenumtypeqwUarabicqxuh%hlh]qy(cdocutils.nodes list_item qz)q{}q|(h$X*Autoscale Group (AG):* An AG can be viewed as a collection of criteria for maintaining or scaling a set of EC2 instances over one or more availability zones. An AG is limited to a single region.h*}q}(h.]h/]h-]h,]h0]uh%hrh]q~hK)q}q(h$X*Autoscale Group (AG):* An AG can be viewed as a collection of criteria for maintaining or scaling a set of EC2 instances over one or more availability zones. An AG is limited to a single region.h%h{h&h'h(hOh*}q(h.]h/]h-]h,]h0]uh2Kh]q(cdocutils.nodes emphasis q)q}q(h$X*Autoscale Group (AG):*h*}q(h.]h/]h-]h,]h0]uh%hh]qhGXAutoscale Group (AG):qq}q(h$Uh%hubah(UemphasisqubhGX An AG can be viewed as a collection of criteria for maintaining or scaling a set of EC2 instances over one or more availability zones. An AG is limited to a single region.qq}q(h$X An AG can be viewed as a collection of criteria for maintaining or scaling a set of EC2 instances over one or more availability zones. An AG is limited to a single region.h%hubeubah(U list_itemqubhz)q}q(h$X*Launch Configuration (LC):* An LC is the set of information needed by the AG to launch new instances - this can encompass image ids, startup data, security groups and keys. Only one LC is attached to an AG.h*}q(h.]h/]h-]h,]h0]uh%hrh]qhK)q}q(h$X*Launch Configuration (LC):* An LC is the set of information needed by the AG to launch new instances - this can encompass image ids, startup data, security groups and keys. Only one LC is attached to an AG.h%hh&h'h(hOh*}q(h.]h/]h-]h,]h0]uh2Kh]q(h)q}q(h$X*Launch Configuration (LC):*h*}q(h.]h/]h-]h,]h0]uh%hh]qhGXLaunch Configuration (LC):qq}q(h$Uh%hubah(hubhGX An LC is the set of information needed by the AG to launch new instances - this can encompass image ids, startup data, security groups and keys. Only one LC is attached to an AG.qq}q(h$X An LC is the set of information needed by the AG to launch new instances - this can encompass image ids, startup data, security groups and keys. Only one LC is attached to an AG.h%hubeubah(hubhz)q}q(h$XQ*Triggers*: A trigger is essentially a set of rules for determining when to scale an AG up or down. These rules can encompass a set of metrics such as average CPU usage across instances, or incoming requests, a threshold for when an action will take place, as well as parameters to control how long to wait after a threshold is crossed. h*}q(h.]h/]h-]h,]h0]uh%hrh]qhK)q}q(h$XP*Triggers*: A trigger is essentially a set of rules for determining when to scale an AG up or down. These rules can encompass a set of metrics such as average CPU usage across instances, or incoming requests, a threshold for when an action will take place, as well as parameters to control how long to wait after a threshold is crossed.h%hh&h'h(hOh*}q(h.]h/]h-]h,]h0]uh2Kh]q(h)q}q(h$X *Triggers*h*}q(h.]h/]h-]h,]h0]uh%hh]qhGXTriggersqq}q(h$Uh%hubah(hubhGXF: A trigger is essentially a set of rules for determining when to scale an AG up or down. These rules can encompass a set of metrics such as average CPU usage across instances, or incoming requests, a threshold for when an action will take place, as well as parameters to control how long to wait after a threshold is crossed.qq}q(h$XF: A trigger is essentially a set of rules for determining when to scale an AG up or down. These rules can encompass a set of metrics such as average CPU usage across instances, or incoming requests, a threshold for when an action will take place, as well as parameters to control how long to wait after a threshold is crossed.h%hubeubah(hubeh(Uenumerated_listqubaubeubh4)q}q(h$Uh%h5h&h'h(h9h*}q(h.]h/]h-]h,]qhah0]qhauh2Kh3hh]q(h@)q}q(h$XCreating a Connectionqh%hh&h'h(hDh*}q(h.]h/]h-]h,]h0]uh2Kh3hh]qhGXCreating a Connectionqq}q(h$hh%hubaubhK)q}q(h$XThe first step in accessing autoscaling is to create a connection to the service. There are two ways to do this in boto. The first is:qh%hh&h'h(hOh*}q(h.]h/]h-]h,]h0]uh2Kh3hh]qhGXThe first step in accessing autoscaling is to create a connection to the service. There are two ways to do this in boto. The first is:qȅq}q(h$hh%hubaubcdocutils.nodes doctest_block q)q}q(h$X}>>> from boto.ec2.autoscale import AutoScaleConnection >>> conn = AutoScaleConnection('', '')h%hh&h'h(U doctest_blockqh*}q(U xml:spaceqUpreserveqh,]h-]h.]h/]h0]uh2K!h3hh]qhGX}>>> from boto.ec2.autoscale import AutoScaleConnection >>> conn = AutoScaleConnection('', '')qӅq}q(h$Uh%hubaubh4)q}q(h$Uh%hh&h'h(h9h*}q(h.]h/]h-]h,]qhah0]qh auh2K%h3hh]q(h@)q}q(h$X"A Note About Regions and Endpointsqh%hh&h'h(hDh*}q(h.]h/]h-]h,]h0]uh2K%h3hh]qhGX"A Note About Regions and Endpointsqᅁq}q(h$hh%hubaubhK)q}q(h$XLike EC2 the Autoscale service has a different endpoint for each region. By default the US endpoint is used. To choose a specific region, instantiate the AutoScaleConnection object with that region's endpoint.qh%hh&h'h(hOh*}q(h.]h/]h-]h,]h0]uh2K&h3hh]qhGXLike EC2 the Autoscale service has a different endpoint for each region. By default the US endpoint is used. To choose a specific region, instantiate the AutoScaleConnection object with that region's endpoint.q酁q}q(h$hh%hubaubh)q}q(h$X_>>> import boto.ec2.autoscale >>> autoscale = boto.ec2.autoscale.connect_to_region('eu-west-1')h%hh&h'h(hh*}q(hhh,]h-]h.]h/]h0]uh2K+h3hh]qhGX_>>> import boto.ec2.autoscale >>> autoscale = boto.ec2.autoscale.connect_to_region('eu-west-1')qq}q(h$Uh%hubaubhK)q}q(h$XNAlternatively, edit your boto.cfg with the default Autoscale endpoint to use::qh%hh&h'h(hOh*}q(h.]h/]h-]h,]h0]uh2K-h3hh]qhGXMAlternatively, edit your boto.cfg with the default Autoscale endpoint to use:qq}q(h$XMAlternatively, edit your boto.cfg with the default Autoscale endpoint to use:h%hubaubcdocutils.nodes literal_block q)q}q(h$X?[Boto] autoscale_endpoint = autoscaling.eu-west-1.amazonaws.comh%hh&h'h(U literal_blockqh*}q(hhh,]h-]h.]h/]h0]uh2K/h3hh]rhGX?[Boto] autoscale_endpoint = autoscaling.eu-west-1.amazonaws.comrr}r(h$Uh%hubaubeubh4)r}r(h$Uh%hh&h'h(h9h*}r(h.]h/]h-]h,]rhah0]rhauh2K3h3hh]r (h@)r }r (h$X!Getting Existing AutoScale Groupsr h%jh&h'h(hDh*}r (h.]h/]h-]h,]h0]uh2K3h3hh]rhGX!Getting Existing AutoScale Groupsrr}r(h$j h%j ubaubhK)r}r(h$X&To retrieve existing autoscale groups:rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2K5h3hh]rhGX&To retrieve existing autoscale groups:rr}r(h$jh%jubaubh)r}r(h$X>>> conn.get_all_groups()rh%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2K7h3hh]rhGX>>> conn.get_all_groups()rr }r!(h$Uh%jubaubhK)r"}r#(h$XNYou will get back a list of AutoScale group objects, one for each AG you have.r$h%jh&h'h(hOh*}r%(h.]h/]h-]h,]h0]uh2K9h3hh]r&hGXNYou will get back a list of AutoScale group objects, one for each AG you have.r'r(}r)(h$j$h%j"ubaubeubeubh4)r*}r+(h$Uh%h5h&h'h(h9h*}r,(h.]h/]h-]h,]r-hah0]r.h auh2K}r?(h$j:h%j8ubaubhk)r@}rA(h$Uh%j*h&Nh(hnh*}rB(h.]h/]h-]h,]h0]uh2Nh3hh]rChq)rD}rE(h$Uh*}rF(huU.h,]h-]h.]hvUh/]h0]hwhxuh%j@h]rG(hz)rH}rI(h$X*Name*: The name of the AG.rJh*}rK(h.]h/]h-]h,]h0]uh%jDh]rLhK)rM}rN(h$jJh%jHh&h'h(hOh*}rO(h.]h/]h-]h,]h0]uh2K?h]rP(h)rQ}rR(h$X*Name*h*}rS(h.]h/]h-]h,]h0]uh%jMh]rThGXNamerUrV}rW(h$Uh%jQubah(hubhGX: The name of the AG.rXrY}rZ(h$X: The name of the AG.h%jMubeubah(hubhz)r[}r\(h$XH*Availability Zones*: The list of availability zones it is defined over.r]h*}r^(h.]h/]h-]h,]h0]uh%jDh]r_hK)r`}ra(h$j]h%j[h&h'h(hOh*}rb(h.]h/]h-]h,]h0]uh2K@h]rc(h)rd}re(h$X*Availability Zones*h*}rf(h.]h/]h-]h,]h0]uh%j`h]rghGXAvailability Zonesrhri}rj(h$Uh%jdubah(hubhGX4: The list of availability zones it is defined over.rkrl}rm(h$X4: The list of availability zones it is defined over.h%j`ubeubah(hubhz)rn}ro(h$X@*Minimum Size*: Minimum number of instances running at one time.rph*}rq(h.]h/]h-]h,]h0]uh%jDh]rrhK)rs}rt(h$jph%jnh&h'h(hOh*}ru(h.]h/]h-]h,]h0]uh2KAh]rv(h)rw}rx(h$X*Minimum Size*h*}ry(h.]h/]h-]h,]h0]uh%jsh]rzhGX Minimum Sizer{r|}r}(h$Uh%jwubah(hubhGX2: Minimum number of instances running at one time.r~r}r(h$X2: Minimum number of instances running at one time.h%jsubeubah(hubhz)r}r(h$X@*Maximum Size*: Maximum number of instances running at one time.rh*}r(h.]h/]h-]h,]h0]uh%jDh]rhK)r}r(h$jh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2KBh]r(h)r}r(h$X*Maximum Size*h*}r(h.]h/]h-]h,]h0]uh%jh]rhGX Maximum Sizerr}r(h$Uh%jubah(hubhGX2: Maximum number of instances running at one time.rr}r(h$X2: Maximum number of instances running at one time.h%jubeubah(hubhz)r}r(h$XP*Launch Configuration (LC)*: A set of instructions on how to launch an instance.rh*}r(h.]h/]h-]h,]h0]uh%jDh]rhK)r}r(h$jh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2KCh]r(h)r}r(h$X*Launch Configuration (LC)*h*}r(h.]h/]h-]h,]h0]uh%jh]rhGXLaunch Configuration (LC)rr}r(h$Uh%jubah(hubhGX5: A set of instructions on how to launch an instance.rr}r(h$X5: A set of instructions on how to launch an instance.h%jubeubah(hubhz)r}r(h$X~*Load Balancer*: An optional ELB load balancer to use. See the ELB tutorial for information on how to create a load balancer. h*}r(h.]h/]h-]h,]h0]uh%jDh]rhK)r}r(h$X}*Load Balancer*: An optional ELB load balancer to use. See the ELB tutorial for information on how to create a load balancer.h%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2KDh]r(h)r}r(h$X*Load Balancer*h*}r(h.]h/]h-]h,]h0]uh%jh]rhGX Load Balancerrr}r(h$Uh%jubah(hubhGXn: An optional ELB load balancer to use. See the ELB tutorial for information on how to create a load balancer.rr}r(h$Xn: An optional ELB load balancer to use. See the ELB tutorial for information on how to create a load balancer.h%jubeubah(hubeh(hubaubhK)r}r(h$XFor the purposes of this tutorial, let's assume we want to create one autoscale group over the us-east-1a and us-east-1b availability zones. We want to have two instances in each availability zone, thus a minimum size of 4. For now we won't worry about scaling up or down - we'll introduce that later when we talk about triggers. Thus we'll set a maximum size of 4 as well. We'll also associate the AG with a load balancer which we assume we've already created, called 'my_lb'.rh%j*h&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2KGh3hh]rhGXFor the purposes of this tutorial, let's assume we want to create one autoscale group over the us-east-1a and us-east-1b availability zones. We want to have two instances in each availability zone, thus a minimum size of 4. For now we won't worry about scaling up or down - we'll introduce that later when we talk about triggers. Thus we'll set a maximum size of 4 as well. We'll also associate the AG with a load balancer which we assume we've already created, called 'my_lb'.rr}r(h$jh%jubaubhK)r}r(h$XOur LC tells us how to start an instance. This will at least include the image id to use, security_group, and key information. We assume the image id, key name and security groups have already been defined elsewhere - see the EC2 tutorial for information on how to create these.rh%j*h&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2KNh3hh]rhGXOur LC tells us how to start an instance. This will at least include the image id to use, security_group, and key information. We assume the image id, key name and security groups have already been defined elsewhere - see the EC2 tutorial for information on how to create these.rr}r(h$jh%jubaubh)r}r(h$XV>>> from boto.ec2.autoscale import LaunchConfiguration >>> from boto.ec2.autoscale import AutoScalingGroup >>> lc = LaunchConfiguration(name='my-launch_config', image_id='my-ami', key_name='my_key_name', security_groups=['my_security_groups']) >>> conn.create_launch_configuration(lc)h%j*h&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2KXh3hh]rhGXV>>> from boto.ec2.autoscale import LaunchConfiguration >>> from boto.ec2.autoscale import AutoScalingGroup >>> lc = LaunchConfiguration(name='my-launch_config', image_id='my-ami', key_name='my_key_name', security_groups=['my_security_groups']) >>> conn.create_launch_configuration(lc)rr}r(h$Uh%jubaubhK)r}r(h$XWe now have created a launch configuration called 'my-launch-config'. We are now ready to associate it with our new autoscale group.rh%j*h&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2KZh3hh]rhGXWe now have created a launch configuration called 'my-launch-config'. We are now ready to associate it with our new autoscale group.rr}r(h$jh%jubaubh)r}r(h$X+>>> ag = AutoScalingGroup(group_name='my_group', load_balancers=['my-lb'], availability_zones=['us-east-1a', 'us-east-1b'], launch_config=lc, min_size=4, max_size=8, connection=conn) >>> conn.create_auto_scaling_group(ag)h%j*h&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kah3hh]rhGX+>>> ag = AutoScalingGroup(group_name='my_group', load_balancers=['my-lb'], availability_zones=['us-east-1a', 'us-east-1b'], launch_config=lc, min_size=4, max_size=8, connection=conn) >>> conn.create_auto_scaling_group(ag)rr}r(h$Uh%jubaubhK)r}r(h$XWe now have a new autoscaling group defined! At this point instances should be starting to launch. To view activity on an autoscale group:rh%j*h&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kch3hh]rhGXWe now have a new autoscaling group defined! At this point instances should be starting to launch. To view activity on an autoscale group:rr}r(h$jh%jubaubh)r}r(h$Xf>>> ag.get_activities() [Activity:Launching a new EC2 instance status:Successful progress:100, ...]h%j*h&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Khh3hh]rhGXf>>> ag.get_activities() [Activity:Launching a new EC2 instance status:Successful progress:100, ...]rr}r(h$Uh%jubaubhK)r}r(h$Xor alternatively:rh%j*h&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kjh3hh]rhGXor alternatively:rr}r(h$jh%jubaubh)r}r(h$X>>> conn.get_all_activities(ag)rh%j*h&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Klh3hh]rhGX>>> conn.get_all_activities(ag)rr}r(h$Uh%jubaubhK)r}r(h$XuThis autoscale group is fairly useful in that it will maintain the minimum size without breaching the maximum size defined. That means if one instance crashes, the autoscale group will use the launch configuration to start a new one in an attempt to maintain its minimum defined size. It knows instance health using the health check defined on its associated load balancer.rh%j*h&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Knh3hh]rhGXuThis autoscale group is fairly useful in that it will maintain the minimum size without breaching the maximum size defined. That means if one instance crashes, the autoscale group will use the launch configuration to start a new one in an attempt to maintain its minimum defined size. It knows instance health using the health check defined on its associated load balancer.rr}r(h$jh%jubaubh4)r}r(h$Uh%j*h&h'h(h9h*}r(h.]h/]h-]h,]r hah0]r h auh2Kuh3hh]r (h@)r }r (h$XScaling a Group Up or Downrh%jh&h'h(hDh*}r(h.]h/]h-]h,]h0]uh2Kuh3hh]rhGXScaling a Group Up or Downrr}r(h$jh%j ubaubhK)r}r(h$XIt can also be useful to scale a group up or down depending on certain criteria. For example, if the average CPU utilization of the group goes above 70%, you may want to scale up the number of instances to deal with demand. Likewise, you might want to scale down if usage drops again. These rules for **how** to scale are defined by *Scaling Policies*, and the rules for **when** to scale are defined by CloudWatch *Metric Alarms*.h%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kvh3hh]r(hGX-It can also be useful to scale a group up or down depending on certain criteria. For example, if the average CPU utilization of the group goes above 70%, you may want to scale up the number of instances to deal with demand. Likewise, you might want to scale down if usage drops again. These rules for rr}r(h$X-It can also be useful to scale a group up or down depending on certain criteria. For example, if the average CPU utilization of the group goes above 70%, you may want to scale up the number of instances to deal with demand. Likewise, you might want to scale down if usage drops again. These rules for h%jubcdocutils.nodes strong r)r}r(h$X**how**h*}r(h.]h/]h-]h,]h0]uh%jh]rhGXhowr r!}r"(h$Uh%jubah(Ustrongr#ubhGX to scale are defined by r$r%}r&(h$X to scale are defined by h%jubh)r'}r((h$X*Scaling Policies*h*}r)(h.]h/]h-]h,]h0]uh%jh]r*hGXScaling Policiesr+r,}r-(h$Uh%j'ubah(hubhGX, and the rules for r.r/}r0(h$X, and the rules for h%jubj)r1}r2(h$X**when**h*}r3(h.]h/]h-]h,]h0]uh%jh]r4hGXwhenr5r6}r7(h$Uh%j1ubah(j#ubhGX$ to scale are defined by CloudWatch r8r9}r:(h$X$ to scale are defined by CloudWatch h%jubh)r;}r<(h$X*Metric Alarms*h*}r=(h.]h/]h-]h,]h0]uh%jh]r>hGX Metric Alarmsr?r@}rA(h$Uh%j;ubah(hubhGX.rB}rC(h$X.h%jubeubhK)rD}rE(h$XFor example, let's configure scaling for the above group based on CPU utilization. We'll say it should scale up if the average CPU usage goes above 70% and scale down if it goes below 40%.rFh%jh&h'h(hOh*}rG(h.]h/]h-]h,]h0]uh2K}h3hh]rHhGXFor example, let's configure scaling for the above group based on CPU utilization. We'll say it should scale up if the average CPU usage goes above 70% and scale down if it goes below 40%.rIrJ}rK(h$jFh%jDubaubhK)rL}rM(h$XFirstly, define some Scaling Policies. These tell Auto Scaling how to scale the group (but not when to do it, we'll specify that later).rNh%jh&h'h(hOh*}rO(h.]h/]h-]h,]h0]uh2Kh3hh]rPhGXFirstly, define some Scaling Policies. These tell Auto Scaling how to scale the group (but not when to do it, we'll specify that later).rQrR}rS(h$jNh%jLubaubhK)rT}rU(h$X;We need one policy for scaling up and one for scaling down.rVh%jh&h'h(hOh*}rW(h.]h/]h-]h,]h0]uh2Kh3hh]rXhGX;We need one policy for scaling up and one for scaling down.rYrZ}r[(h$jVh%jTubaubh)r\}r](h$X>>> from boto.ec2.autoscale import ScalingPolicy >>> scale_up_policy = ScalingPolicy( name='scale_up', adjustment_type='ChangeInCapacity', as_name='my_group', scaling_adjustment=1, cooldown=180) >>> scale_down_policy = ScalingPolicy( name='scale_down', adjustment_type='ChangeInCapacity', as_name='my_group', scaling_adjustment=-1, cooldown=180)h%jh&h'h(hh*}r^(hhh,]h-]h.]h/]h0]uh2Kh3hh]r_hGX>>> from boto.ec2.autoscale import ScalingPolicy >>> scale_up_policy = ScalingPolicy( name='scale_up', adjustment_type='ChangeInCapacity', as_name='my_group', scaling_adjustment=1, cooldown=180) >>> scale_down_policy = ScalingPolicy( name='scale_down', adjustment_type='ChangeInCapacity', as_name='my_group', scaling_adjustment=-1, cooldown=180)r`ra}rb(h$Uh%j\ubaubhK)rc}rd(h$XEThe policy objects are now defined locally. Let's submit them to AWS.reh%jh&h'h(hOh*}rf(h.]h/]h-]h,]h0]uh2Kh3hh]rghGXEThe policy objects are now defined locally. Let's submit them to AWS.rhri}rj(h$jeh%jcubaubh)rk}rl(h$Xa>>> conn.create_scaling_policy(scale_up_policy) >>> conn.create_scaling_policy(scale_down_policy)h%jh&h'h(hh*}rm(hhh,]h-]h.]h/]h0]uh2Kh3hh]rnhGXa>>> conn.create_scaling_policy(scale_up_policy) >>> conn.create_scaling_policy(scale_down_policy)rorp}rq(h$Uh%jkubaubhK)rr}rs(h$XNow that the polices have been digested by AWS, they have extra properties that we aren't aware of locally. We need to refresh them by requesting them back again.rth%jh&h'h(hOh*}ru(h.]h/]h-]h,]h0]uh2Kh3hh]rvhGXNow that the polices have been digested by AWS, they have extra properties that we aren't aware of locally. We need to refresh them by requesting them back again.rwrx}ry(h$jth%jrubaubh)rz}r{(h$X>>> scale_up_policy = conn.get_all_policies( as_group='my_group', policy_names=['scale_up'])[0] >>> scale_down_policy = conn.get_all_policies( as_group='my_group', policy_names=['scale_down'])[0]h%jh&h'h(hh*}r|(hhh,]h-]h.]h/]h0]uh2Kh3hh]r}hGX>>> scale_up_policy = conn.get_all_policies( as_group='my_group', policy_names=['scale_up'])[0] >>> scale_down_policy = conn.get_all_policies( as_group='my_group', policy_names=['scale_down'])[0]r~r}r(h$Uh%jzubaubhK)r}r(h$XSpecifically, we'll need the Amazon Resource Name (ARN) of each policy, which will now be a property of our ScalingPolicy objects.rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGXSpecifically, we'll need the Amazon Resource Name (ARN) of each policy, which will now be a property of our ScalingPolicy objects.rr}r(h$jh%jubaubhK)r}r(h$X[Next we'll create CloudWatch alarms that will define when to run the Auto Scaling Policies.rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGX[Next we'll create CloudWatch alarms that will define when to run the Auto Scaling Policies.rr}r(h$jh%jubaubh)r}r(h$Xb>>> import boto.ec2.cloudwatch >>> cloudwatch = boto.ec2.cloudwatch.connect_to_region('us-west-2')h%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]rhGXb>>> import boto.ec2.cloudwatch >>> cloudwatch = boto.ec2.cloudwatch.connect_to_region('us-west-2')rr}r(h$Uh%jubaubhK)r}r(h$XIt makes sense to measure the average CPU usage across the whole Auto Scaling Group, rather than individual instances. We express that as CloudWatch *Dimensions*.h%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]r(hGXIt makes sense to measure the average CPU usage across the whole Auto Scaling Group, rather than individual instances. We express that as CloudWatch rr}r(h$XIt makes sense to measure the average CPU usage across the whole Auto Scaling Group, rather than individual instances. We express that as CloudWatch h%jubh)r}r(h$X *Dimensions*h*}r(h.]h/]h-]h,]h0]uh%jh]rhGX Dimensionsrr}r(h$Uh%jubah(hubhGX.r}r(h$X.h%jubeubh)r}r(h$X;>>> alarm_dimensions = {"AutoScalingGroupName": 'my_group'}rh%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]rhGX;>>> alarm_dimensions = {"AutoScalingGroupName": 'my_group'}rr}r(h$Uh%jubaubhK)r}r(h$XECreate an alarm for when to scale up, and one for when to scale down.rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGXECreate an alarm for when to scale up, and one for when to scale down.rr}r(h$jh%jubaubh)r}r(h$X>>> from boto.ec2.cloudwatch import MetricAlarm >>> scale_up_alarm = MetricAlarm( name='scale_up_on_cpu', namespace='AWS/EC2', metric='CPUUtilization', statistic='Average', comparison='>', threshold='70', period='60', evaluation_periods=2, alarm_actions=[scale_up_policy.policy_arn], dimensions=alarm_dimensions) >>> cloudwatch.create_alarm(scale_up_alarm)h%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]rhGX>>> from boto.ec2.cloudwatch import MetricAlarm >>> scale_up_alarm = MetricAlarm( name='scale_up_on_cpu', namespace='AWS/EC2', metric='CPUUtilization', statistic='Average', comparison='>', threshold='70', period='60', evaluation_periods=2, alarm_actions=[scale_up_policy.policy_arn], dimensions=alarm_dimensions) >>> cloudwatch.create_alarm(scale_up_alarm)rr}r(h$Uh%jubaubh)r}r(h$X>>> scale_down_alarm = MetricAlarm( name='scale_down_on_cpu', namespace='AWS/EC2', metric='CPUUtilization', statistic='Average', comparison='<', threshold='40', period='60', evaluation_periods=2, alarm_actions=[scale_down_policy.policy_arn], dimensions=alarm_dimensions) >>> cloudwatch.create_alarm(scale_down_alarm)h%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]rhGX>>> scale_down_alarm = MetricAlarm( name='scale_down_on_cpu', namespace='AWS/EC2', metric='CPUUtilization', statistic='Average', comparison='<', threshold='40', period='60', evaluation_periods=2, alarm_actions=[scale_down_policy.policy_arn], dimensions=alarm_dimensions) >>> cloudwatch.create_alarm(scale_down_alarm)rr}r(h$Uh%jubaubhK)r}r(h$X4Auto Scaling will now create a new instance if the existing cluster averages more than 70% CPU for two minutes. Similarly, it will terminate an instance when CPU usage sits below 40%. Auto Scaling will not add or remove instances beyond the limits of the Scaling Group's 'max_size' and 'min_size' properties.rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGX4Auto Scaling will now create a new instance if the existing cluster averages more than 70% CPU for two minutes. Similarly, it will terminate an instance when CPU usage sits below 40%. Auto Scaling will not add or remove instances beyond the limits of the Scaling Group's 'max_size' and 'min_size' properties.rr}r(h$jh%jubaubhK)r}r(h$X2To retrieve the instances in your autoscale group:rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGX2To retrieve the instances in your autoscale group:rr}r(h$jh%jubaubh)r}r(h$X>>> import boto.ec2 >>> ec2 = boto.ec2.connect_to_region('us-west-2) >>> group = conn.get_all_groups(names=['my_group'])[0] >>> instance_ids = [i.instance_id for i in group.instances] >>> instances = ec2.get_only_instances(instance_ids)h%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]rhGX>>> import boto.ec2 >>> ec2 = boto.ec2.connect_to_region('us-west-2) >>> group = conn.get_all_groups(names=['my_group'])[0] >>> instance_ids = [i.instance_id for i in group.instances] >>> instances = ec2.get_only_instances(instance_ids)rr}r(h$Uh%jubaubhK)r}r(h$XLTo delete your autoscale group, we first need to shutdown all the instances:rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGXLTo delete your autoscale group, we first need to shutdown all the instances:rr}r(h$jh%jubaubh)r}r(h$X>>> ag.shutdown_instances()rh%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]rhGX>>> ag.shutdown_instances()rr}r(h$Uh%jubaubhK)r}r(h$XJOnce the instances have been shutdown, you can delete the autoscale group:rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGXJOnce the instances have been shutdown, you can delete the autoscale group:rr}r(h$jh%jubaubh)r}r(h$X>>> ag.delete()rh%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]rhGX>>> ag.delete()rr}r(h$Uh%jubaubhK)r}r(h$X.You can also delete your launch configuration:rh%jh&h'h(hOh*}r(h.]h/]h-]h,]h0]uh2Kh3hh]rhGX.You can also delete your launch configuration:rr}r(h$jh%jubaubh)r}r(h$X>>> lc.delete()rh%jh&h'h(hh*}r(hhh,]h-]h.]h/]h0]uh2Kh3hh]r hGX>>> lc.delete()r r }r (h$Uh%jubaubeubeubeubeh$UU transformerr NU footnote_refsr}rUrefnamesr}rUsymbol_footnotesr]rUautofootnote_refsr]rUsymbol_footnote_refsr]rU citationsr]rh3hU current_linerNUtransform_messagesr]rcdocutils.nodes system_message r)r}r(h$Uh*}r (h.]UlevelKh,]h-]Usourceh'h/]h0]UlineKUtypeUINFOr!uh]r"hK)r#}r$(h$Uh*}r%(h.]h/]h-]h,]h0]uh%jh]r&hGX3Hyperlink target "autoscale-tut" is not referenced.r'r(}r)(h$Uh%j#ubah(hOubah(Usystem_messager*ubaUreporterr+NUid_startr,KU autofootnotesr-]r.U citation_refsr/}r0Uindirect_targetsr1]r2Usettingsr3(cdocutils.frontend Values r4or5}r6(Ufootnote_backlinksr7KUrecord_dependenciesr8NU rfc_base_urlr9Uhttp://tools.ietf.org/html/r:U tracebackr;Upep_referencesr<NUstrip_commentsr=NU toc_backlinksr>Uentryr?U language_coder@UenrAU datestamprBNU report_levelrCKU _destinationrDNU halt_levelrEKU strip_classesrFNhDNUerror_encoding_error_handlerrGUbackslashreplacerHUdebugrINUembed_stylesheetrJUoutput_encoding_error_handlerrKUstrictrLU sectnum_xformrMKUdump_transformsrNNU docinfo_xformrOKUwarning_streamrPNUpep_file_url_templaterQUpep-%04drRUexit_status_levelrSKUconfigrTNUstrict_visitorrUNUcloak_email_addressesrVUtrim_footnote_reference_spacerWUenvrXNUdump_pseudo_xmlrYNUexpose_internalsrZNUsectsubtitle_xformr[U source_linkr\NUrfc_referencesr]NUoutput_encodingr^Uutf-8r_U source_urlr`NUinput_encodingraU utf-8-sigrbU_disable_configrcNU id_prefixrdUU tab_widthreKUerror_encodingrfUUTF-8rgU_sourcerhh'Ugettext_compactriU generatorrjNUdump_internalsrkNU smart_quotesrlU pep_base_urlrmUhttp://www.python.org/dev/peps/rnUsyntax_highlightroUlongrpUinput_encoding_error_handlerrqjLUauto_id_prefixrrUidrsUdoctitle_xformrtUstrip_elements_with_classesruNU _config_filesrv]Ufile_insertion_enabledrwU raw_enabledrxKU dump_settingsryNubUsymbol_footnote_startrzKUidsr{}r|(hjhhUhj*hh5hjhh5hhhhuUsubstitution_namesr}}r~h(h3h*}r(h.]h,]h-]Usourceh'h/]h0]uU footnotesr]rUrefidsr}rh]rh"asub.