Auto Scaling
Developer Guide (API Version 2011-01-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Shut Down an Auto-Scaled, Load-Balanced Application

In this example, you completely shut down an application that uses Auto Scaling, Elastic Load Balancing and Amazon CloudWatch alarms. For an example of how to set up an Auto Scaling application that uses Elastic Load Balancing and Amazon CloudWatch alarms, see Auto Scaling With Alarms And Load Balancing.

All Amazon EC2 instances for an online application are shut down. All Auto Scaling groups and Amazon CloudWatch alarms associated with the application are deleted.

In this example, we assume you have an application (associated with a LoadBalancer named MyLB) running on a set of Amazon EC2 instances in an Auto Scaling group named MyAutoScalingGroup. The application is load-balanced, and is also auto-scaled through corresponding scaling triggers:

  • MyHighCPUAlarm that initiates MyScaleUpPolicy

  • MyLowCPUAlarm that initiates MyScaleDownPolicy

[Note]Note

This scenario is for an application that is both load-balanced and auto-scaled. If you aren't using Elastic Load Balancing, omit step 3 from the following examples.

API Example

To shut down an auto-scaled, load-balanced application

  1. Delete MyScalingGroup:

    1. Call UpdateAutoScalingGroup with the following parameters:

      • AutoScalingGroupName = MyAutoScalingGroup

      • MinSize = 0

      • MaxSize = 0

    2. Verify that your changes to MyAutoScalingGroup have taken effect by doing the following:

      1. Call DescribeAutoScalingGroups with MyAutoScalingGroup as a request parameter to verify that there are no instances left in the group.

      2. Call DescribeScalingActivites with MyAutoScalingGroup as a request parameter to verify that all scaling activities have completed.

    3. Call DeleteAutoScalingGroup with the following parameters:

      • AutoScalingGroupName = MyAutoScalingGroup

      [Note]Note

      Auto Scaling deletes any policies associated with the Auto Scaling group you are deleting.

    4. Call DeleteLaunchConfiguration with the following parameters:

      • LaunchConfigurationName = MyLC

  2. Call DeleteAlarms from the Amazon CloudWatch API with the following parameters:

    • AlarmNames.member.1 = MyHighCPUAlarm

    • AlarmNames.member.2 = MyLowCPUAlarm

  3. Delete the LoadBalancer.

    1. Call DeleteLoadBalancer from the Elastic Load Balancing API with the following parameters:

      LoadBalancerName = MyLB

The application is completely shut down.

For documentation on DeleteLoadBalancer, refer to the API Reference of the Elastic Load Balancing Developer Guide.

Command Line Tools Example

To shut down an auto-scaled, load-balanced application

  1. Delete MyAutoScalingGroup:

    1. Use the Auto Scaling as-update-auto-scaling-group command to change the minimum and maximum size.

      PROMPT>as-update-auto-scaling-group MyAutoScalingGroup --min-size 0 --max-size 0

      Auto Scaling returns the following:

      OK-AutoScaling Group updated
    2. Verify that no instances are in your Auto Scaling group by using the Auto Scaling as-describe-auto-scaling-groups command.

      PROMPT>as-describe-auto-scaling-groups MyAutoScalingGroup --headers

      Auto Scaling might report that the state of your instances is Terminating because the termination process can take a few minutes:

      AUTO-SCALING-GROUP  GROUP-NAME            LAUNCH-CONFIG          AVAILABILITY-ZONES  MIN-SIZE  MAX-SIZE  DESIRED-CAPACITY
      AUTO-SCALING-GROUP  MyAutoScalingGroup    MyLC                   us-east-1a          0         0         0
      INSTANCE  INSTANCE-ID  AVAILABILITY-ZONE  STATE        STATUS   LAUNCH-CONFIG
      INSTANCE  i-xxxxxxxx   us-east-1b         Terminating  Healthy  MyLC
      INSTANCE  i-xxxxxxxx   us-east-1a         Terminating  Healthy  MyLC	

      After the termination process completes, calls to this command will report that no more instances remain in the Auto Scaling group:

      AUTO-SCALING-GROUP  GROUP-NAME            LAUNCH-CONFIG          AVAILABILITY-ZONES  MIN-SIZE  MAX-SIZE  DESIRED-CAPACITY
      AUTO-SCALING-GROUP  MyAutoScalingGroup    MyLC                   us-east-1a          0         0         0	
    3. Use the Auto Scaling as-delete-auto-scaling-group command.

      PROMPT>as-delete-auto-scaling-group MyAutoScalingGroup

      Auto Scaling returns the following:

      Are you sure you want to delete this AutoScalingGroup?  [Ny]

      Enter y to delete the AutoScalingGroup.

      Auto Scaling returns the following:

      OK-Deleted AutoScalingGroup
      [Note]Note

      Auto Scaling deletes any policies associated with the Auto Scaling group you are deleting.

    4. Use the Auto Scaling as-delete-launch-config command to delete the launch configuration.

      PROMPT>as-delete-launch-config MyLC

      Auto Scaling returns the following:

      Are you sure you want to delete this launch configuration? [Ny]

      Enter y to delete the Launch Configuration.

      Auto Scaling returns the following:

      OK-Deleted launch configuration
  2. Delete the Amazon CloudWatch alarms.

    1. Use the Amazon CloudWatch mon-delete-alarms command.

      PROMPT>mon-delete-alarms MyHighCPUAlarm MyLowCPUAlarm

      Auto Scaling returns the following:

      Are you sure you want to delete these alarms?  [Ny]y

      Enter y to delete the alarms.

      Auto Scaling returns the following:

      OK-Deleted alarms
  3. Delete the load balancer with the Elastic Load Balancing elb-delete-lb command.

    PROMPT>elb-delete-lb  MyLB

    Elastic Load Balancing returns the following:

    Warning: Deleting a LoadBalancer can lead to service disruption to any customers 
    connected to the LoadBalancer. Are you sure you want to delete 
    this LoadBalancer? [Ny]

    Enter y to delete the LoadBalancer

    Elastic Load Balancing returns the following:

    OK-Deleting LoadBalancer

The application is completely shut down.