Basic Auto Scaling configuration on AWS

Auto Scaling

The following configuration allows me to sleep at night. It ensures that at least one EC2 instance will be running at any one time.  The Auto Scaling CLI provided by Amazon is a simple tool that’s required for this configuration. To successfully configure auto scaling you need to follow these 2 steps:

1. Create launch configuration
2. Create Auto Scaling Group

So here we go:

  • Download and install Auto Scaling CLI from here
  • Create launch configuration
    as-create-launch-config MyLaunchConfig --image-id ami-xxxxxxxx --instance-type m1.small --user-data-file --group mysecuritygroup

Successful creation should return

OK-Created launch config
  • Greate Auto Scaling Group
    as-create-auto-scaling-group MyGroup --launch-configuration MyLaunchConfig --availability-zones us-west-1a us-west-1b --min-size 1 --max-size 1 --load-balancers my-load-balancer
  • You can then verify your Auto Scaling group
    as-describe-auto-scaling-groups --headers
  • To verify that MyGroup contains an EC2 instance:
    as-describe-auto-scaling-instances --headers

Be aware of the fact that your Auto Scaling is now configured and running.

To Remove All EC2 Instances from the Group

  • You must terminate all EC2 instances in an Auto Scaling group before you can delete the group. A simple way to terminate all instances in a group is to update the group so that both the minimum size and maximum size are set to zero.
    as-update-auto-scaling-group MyGroup --min-size 0 --max-size 0

This should terminate the EC2 instance for this auto scaling group. You can run the ‘describe’ command to verify this

  • Delete Auto Scaling group
    as-delete-auto-scaling-group MyGroup
    Are you sure you want to delete this AutoScalingGroup? [Y/N]

Press Y to confirm deletion and you should see this:

OK-Deleted AutoScalingGroup

Now delete the configuration

as-delete-launch-config MyLaunchConfig
Are you sure you want to delete this launch configuration? [Y/N]

Press Y to confirm

OK-Deleted launch configuration