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 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 Availability 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.

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 Availability Zones. Incoming traffic is 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 Availability 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.

Expanding Applications Using the AWS CLI

In this example, you expand the availability of your application in EC2-Classic to an additional Availability Zone.

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

  1. Update the Auto Scaling group using the following update-auto-scaling-group command:

    aws autoscaling update-auto-scaling-group --auto-scaling-group-name my-lb-asg --availability-zone-names "us-west-2a" "us-west-2b" "us-west-2c" --min-size 3
  2. Verify that the instances in the new Availability Zone are ready to accept traffic from the load balancer using the following describe-auto-scaling-groups command:

    aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name my-lb-asg

    The following is example output that indicates that the instances are ready:

    {
        "AutoScalingGroups": [
            {
                "AutoScalingGroupARN": "arn",
                "HealthCheckGracePeriod": 300,
                "SuspendedProcesses": [],
                "DesiredCapacity": 3,
                "Tags": [],
                "EnabledMetrics": [],
                "LoadBalancerNames": [
                    "my-lb"
                ],
                "AutoScalingGroupName": "my-lb-asg",
                "DefaultCooldown": 300,
                "MinSize": 3,
                "Instances": [
                    {
                        "InstanceId": "i-9823ca95",
                        "AvailabilityZone": "us-west-2b",
                        "HealthStatus": "Healthy",
                        "LifecycleState": "InService",
                        "LaunchConfigurationName": "my-lc"
                    },
                    {
                        "InstanceId": "i-a42d27a8",
                        "AvailabilityZone": "us-west-2a",
                        "HealthStatus": "Healthy",
                        "LifecycleState": "InService",
                        "LaunchConfigurationName": "my-lc"
                    },
                    {
                        "InstanceId": "i-545dc19d",
                        "AvailabilityZone": "us-west-2c",
                        "HealthStatus": "Healthy",
                        "LifecycleState": "InService",
                        "LaunchConfigurationName": "my-lc"
                    }
                ],
                "MaxSize": 6,
                "VPCZoneIdentifier": null,
                "TerminationPolicies": [
                    "Default"
                ],
                "LaunchConfigurationName": "my-lc",
                "CreatedTime": "2015-03-02T01:28:08.398Z",
                "AvailabilityZones": [
                    "us-west-2c",
                    "us-west-2b",
                    "us-west-2a"
                ],
                "HealthCheckType": "ELB"
            }
        ]
    }
  3. Update the load balancer to route traffic to the new Availability Zone using the following enable-availability-zones-for-load-balancer command. Traffic is routed equally among all the enabled Availability Zones.

    aws elb enable-availability-zones-for-load-balancer --load-balancer-name my-lb --availability-zones us-west-2c

    The following is example output:

    {
      "AvailabilityZones": [
        "us-west-2a",
        "us-west-2b",
        "us-west-2c"
      ]
    }