Auto Scaling
Developer Guide (API Version 2011-01-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

Expand Your Scaled and Load-Balanced Application to an Additional Availability Zone

When one Availability Zone becomes unhealthy or unavailable, Auto Scaling launches new instances in an unaffected Availability Zone. When the unhealthy Availability Zone returns to a healthy state, Auto Scaling automatically redistributes the application instances evenly across all of the designated Availability Zones for your Auto Scaling group. Auto Scaling does this by attempting to launch new instances in the Availability Zone with the fewest instances. If the attempt fails, however, Auto Scaling attempts to launch in other zones until it succeeds.

An Auto Scaling group can contain EC2 instances that come from one or more Availability Zones within the same region. However, an Auto Scaling group cannot span multiple regions. For information about the regions and Availability Zones supported by Auto Scaling, see Regions and Endpoints in the Amazon Web Services General Reference.

You can set up your load balancer to distribute incoming requests across EC2 instances in a single Availability Zone or multiple Availability Zones within a region. The load balancer does not distribute traffic across regions. For critical applications, we recommend that you distribute incoming traffic across multiple Availability Zones by registering your Auto Scaling group in multiple Availability Zones and then enabling your load balancer in each of those zones. Incoming traffic s load balanced equally across all the Availability Zones enabled for your load balancer.

If your load balancer detects unhealthy EC2 instances in an enabled Availability Zone, it stops routing traffic to those instances. Instead, it spreads the load across the remaining healthy instances. If all instances in an Availability Zone are unhealthy, but you have instances in other Availability Zones, Elastic Load Balancing routes traffic to your registered and healthy instances in those other zones. It resumes load balancing to the original instances when they have been restored to a healthy state and are registered with your load balancer.

You can expand the availability of your scaled and load-balanced application by adding a new Availability Zone to your Auto Scaling group and then enabling that Availability Zone for your load balancer. After you've enabled the new Availability Zone, the load balancer begins to route traffic equally among all the enabled Availability Zones.

You can use the Auto Scaling command line interface along with the Elastic Load Balancing CLI to add an Availability Zone to your application. You can also use the Query API. For information about installing the Auto Scaling CLI, see Install the Auto Scaling CLI. For information about installing the Elastic Load Balancing CLI, see Installing the Command Line Interface in the Elastic Load Balancing Developer Guide. For information about creating a Query request, see Use Query Requests to Call Auto Scaling APIs.

Expanding Applications Using the Command Line Interface

In this rocedure, expand the availability of your application to an additional Availability Zone, us-east-1c.

To expand a scaled, load-balanced application to an additional Availability Zone using the CLi

  1. Use the as-update-auto-scaling-group command and specify the following values:

    • Auto Scaling group name = my-test-asg-lbs

    • Availability Zones = us-east-1a, us-east-1b, us-east-1c

    • Min size = 3

    Your command should look similar to the following example:

    as-update-auto-scaling-group my-test-asg-lbs --availability-zones us-east-1a, us-east-1b, us-east-1c --min-size 3

    You should get a confirmation similar to the following example:

    OK-Updated AutoScalingGroup
  2. Use the as-describe-auto-scaling-groups command and specify the following value:

    • Auto Scaling group name = my-test-asg-lbs

    Your command should look similar to the following example:

    as-describe-auto-scaling-groups my-test-asg-lbs --headers

    Auto Scaling responds with details about the group and instances launched. The information you get should be similar to the following example:

    AUTO-SCALING-GROUP  GROUP-NAME       LAUNCH-CONFIG  AVAILABILITY-ZONES  LOAD-BALANCERS  MIN-SIZE  MAX-SIZE  DESIRED-CAPACITY  TERMINATION-POLICIES
    AUTO-SCALING-GROUP  my-test-asg-lbs  my-test-lc    us-east-1c,us-east-1b,us-east-1a  my-test-asg-loadbalancer  3         6         3     Default
    
    INSTANCE  INSTANCE-ID  AVAILABILITY-ZONE  STATE      STATUS   LAUNCH-CONFIG
    INSTANCE  i-78e60b1b   us-east-1b         InService  Healthy  my-test-lc
    INSTANCE  i-dd4b2eb2   us-east-1c         InService  Healthy  my-test-lc
    INSTANCE  i-48a1cf29   us-east-1a         InService  Healthy  my-test-lc
    

    When the status of each of the new instances in the Auto Scaling group in the new Availability Zone changes to InService, this indicates that the instances are now ready to accept traffic from Elastic Load Balancing. You can then proceed to the next step.

    Note

    When you call the elb-enable-zones-for-lb command, the load balancer begins to route traffic equally among all of the enabled Availability Zones.

  3. Use the Elastic Load Balancing elb-enable-zones-for-lb command by specifying the following values:

    • Load balancer name = my-test-asg-loadbalancer

    • Availability Zone = us-east-1c

    Your command should look similar to the following example:

    elb-enable-zones-for-lb  my-test-asg-loadbalancer   --availability-zones us-east-1c --headers

    Elastic Load Balancing responds with a list of Availability Zones enabled for the load balancer. The information you get should be similar to the following example:

    AVAILABILITY_ZONES  AVAILABILITY-ZONES
    AVAILABILITY_ZONES  us-east-1a, us-east-1b, us-east-1c

You have load-balanced your Amazon EC2 application across three Availability Zones and have scaled it in each zone.

Expanding Applications Using the Query API

In this example, you learn how to expand the availability of your application to an additional Availability Zone, us-east-1c.

To expand a scaled, load-balanced application to an additional Availability Zone

  1. Call the UpdateAutoScalingGroup action and specify the following parameters:

    • AutoScalingGroupName = my-test-asg

    • AvailabilityZones.member.1 = us-east-1a

    • AvailabilityZones.member.2 = us-east-1b

    • AvailabilityZones.member.3 = us-east-1c

    • MinSize = 3

    Your request should look similar to the following example:

    https://autoscaling.amazonaws.com/?AutoScalingGroupName=my-test-asg-lbs
    &AvailabilityZones.member.1=us-east-1a
    &AvailabilityZones.member.2=us-east-1b
    &AvailabilityZones.member.3=us-east-1c
    &MinSize=3
    &Version=2011-01-01
    &Action=UpdateAutoScalingGroup
    &AUTHPARAMS

    If your request was successful, you should get a confirmation similar to the following example:

    <UpdateAutoScalingGroupResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
      <ResponseMetadata>
        <RequestId>325f71b3-ac46-11e2-9cae-61a8EXAMPLE</RequestId>
      </ResponseMetadata>
    </UpdateAutoScalingGroupResponse>
  2. Call the DescribeAutoScalingGroups action and specify the following parameter:

    • AutoScalingGroupNames.member.1 = my-test-asg-lbs

    Your request should look similar to the following example:

    https://autoscaling.amazonaws.com/?AutoScalingGroupNames.member.1=my-test-asg-lbs
    &MaxRecords=20
    &Action=DescribeAutoScalingGroups
    &AUTHPARAMS     
  3. The response includes details about the group and instances launched. The information you get should be similar to the following example:

    <DescribeAutoScalingGroupsResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
      <DescribeAutoScalingGroupsResult>
        <AutoScalingGroups>
          <member>
            <Tags/>
            <SuspendedProcesses/>
            <AutoScalingGroupName>my-test-asg-lbs</AutoScalingGroupName>
            <HealthCheckType>ELB</HealthCheckType>
            <CreatedTime>2013-04-21T11:12:17.795Z</CreatedTime>
            <EnabledMetrics/>
            <LaunchConfigurationName>my-test-lc</LaunchConfigurationName>
            <Instances>
              <member>
                <HealthStatus>Healthy</HealthStatus>
                <AvailabilityZone>us-east-1a</AvailabilityZone>
                <InstanceId>i-44a7b627</InstanceId>
                <LaunchConfigurationName>my-test-lc</LaunchConfigurationName>
                <LifecycleState>InService</LifecycleState>
              </member>
              <member>
                <HealthStatus>Healthy</HealthStatus>
                <AvailabilityZone>us-east-1b</AvailabilityZone>
                <InstanceId>i-c34f20a3</InstanceId>
                <LaunchConfigurationName>my-test-lc</LaunchConfigurationName>
                <LifecycleState>InService</LifecycleState>
              </member>
              <member>
                <HealthStatus>Healthy</HealthStatus>
                <AvailabilityZone>us-east-1c</AvailabilityZone>
                <InstanceId>i-98562cf1</InstanceId>
                <LaunchConfigurationName>my-test-lc</LaunchConfigurationName>
                <LifecycleState>InService</LifecycleState>
              </member>
            </Instances>
            <DesiredCapacity>3</DesiredCapacity>
            <AvailabilityZones>
              <member>us-east-1c</member>
              <member>us-east-1b</member>
              <member>us-east-1a</member>
            </AvailabilityZones>
            <LoadBalancerNames>
              <member>my-test-asg-loadbalancer</member>
            </LoadBalancerNames>
            <MinSize>3</MinSize>
            <VPCZoneIdentifier/>
            <HealthCheckGracePeriod>300</HealthCheckGracePeriod>
            <DefaultCooldown>300</DefaultCooldown>
            <AutoScalingGroupARN>arn:aws:autoscaling:us-east-1:803981987763:autoScalingGroup:e8b084c9-8cad-444a-8381-c97b778e0fc0:autoScalingGroupName/my-test-asg-lbs</AutoScalingGroupARN>
            <TerminationPolicies>
              <member>Default</member>
            </TerminationPolicies>
            <MaxSize>6</MaxSize>
          </member>
        </AutoScalingGroups>
      </DescribeAutoScalingGroupsResult>
      <ResponseMetadata>
        <RequestId>084332c2-ac57-11e2-b92b-45061efc08bd</RequestId>
      </ResponseMetadata>
    </DescribeAutoScalingGroupsResponse>
    

    Check the status of the instances in the <LifecycleState> field of all three instances. When the status of each of the new instances in the new Availability Zone appears as InService, indicating that the instances are now recognized by the load balancer and ready, proceed to the next step.

    Note

    When you call EnableAvailabilityZonesForLoadBalancer, the load balancer begins to route traffic equally among all the enabled Availability Zones.

  4. Call the EnableAvailabilityZonesForLoadBalancer action by specifying the following parameters:

    • AvailabilityZones = us-east-1c

    • LoadBalancerName = my-test-asg-loadbalancer

    Your request should look similar to the following example:

    https://elasticloadbalancing.amazonaws.com/?AvailabilityZones.member.1=us-east-1c
    &LoadBalancerName=my-test-asg-loadbalancer
    &Version=2012-06-01
    &Action=EnableAvalabilityZonesForLoadBalancer
    &AUTHPARAMS
  5. The response includes a list of Availability Zones enabled for the load balancer. The information you get should be similar to the following example:

    <EnableAvailabilityZonesForLoadBalancerResponse xmlns="http://elasticloadbalancng.amazonaws.com/doc/2012-06-01/">
      <EnableAvailabilityZonesForLoadBalancerResult>
        <AvailabilityZones>
          <member>us-east-1c</member>
          <member>us-east-1b</member>
          <member>us-east-1a</member>
        </AvailabilityZones>
      </EnableAvailabilityZonesForLoadBalancerResult>
      <ResponseMetadata>
        <RequestId>1ae1f97a-ac59-11e2-ac73-fffddEXAMPLE</RequestId>
      </ResponseMetadata>
    </EnableAvailabilityZonesForLoadBalancerResponse>

You have load-balanced your Amazon EC2 application across three Availability Zones and have scaled it in each zone.