Auto Scaling
Developer Guide
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.

Add an Availability Zone Using the Console

Use the following procedure to expand your Auto Scaling group to an additional subnet (EC2-VPC) or Availability Zone (EC2-Classic).

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, under Auto Scaling, click Auto Scaling Groups.

  3. Select your group.

  4. In the bottom pane, on the Details tab, click Edit.

  5. Do one of the following:

    • [EC2-VPC] In Subnet(s), select the subnet corresponding to the Availability Zone.

    • [EC2-Classic] In Availability Zones(s), select the Availability Zone.

  6. Click Save.

  7. In the navigation pane, under NETWORK & SECURITY, click Load Balancers.

  8. Select your load balancer.

  9. In the bottom pane, on the Instances tab, click Edit Availability Zones.

  10. Do one of the following:

    • [EC2-VPC] In the Add and Remove Subnets dialog box, under Available Subnets, click the icon in the Action column for the subnet to add. The subnet is moved under Selected Subnets.

    • [EC2-Classic] In the Add and Remove Availability Zones dialog box, select the Availability Zone to add.

  11. Click Save.

Add an Availability Zone Using the AWS CLI

If your load balancer is for EC2-VPC, you'll add a subnet. If your load balancer is for EC2-Classic, you'll add an Availability Zone.

EC2-VPC

In this example, you expand your Auto Scaling group in EC2-VPC to an additional subnet.

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

  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 --vpc-zone-identifier subnet-41767929 subnet-cb663da2 --min-size 2
  2. Verify that the instances in the new subnet 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": 2,
                "Tags": [],
                "EnabledMetrics": [],
                "LoadBalancerNames": [
                    "my-lb"
                ],
                "AutoScalingGroupName": "my-lb-asg",
                "DefaultCooldown": 300,
                "MinSize": 2,
                "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"
                    }
                ],
                "MaxSize": 4,
                "VPCZoneIdentifier": "subnet-41767929,subnet-cb663da2",
                "TerminationPolicies": [
                    "Default"
                ],
                "LaunchConfigurationName": "my-lc",
                "CreatedTime": "2015-03-02T01:28:08.398Z",
                "AvailabilityZones": [
                    "us-west-2b",
                    "us-west-2a"
                ],
                "HealthCheckType": "ELB"
            }
        ]
    }
  3. Update the load balancer to route traffic to the new subnet using the following attach-load-balancer-to-subnets command:

    aws elb attach-load-balancer-to-subnets --load-balancer-name my-lb --subnets subnet-41767929

    The following is example output:

    {
        "Subnets": [
            "subnet-41767929",
            "subnet-cb663da2"
        ]
    }

EC2-Classic

In this example, you expand your Auto Scaling group 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-zones 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"
      ]
    }