AWS Auto Scaling – Add or Remove availability zone from a region using cli

AWS Auto Scaling – Add or Remove availability zone from a region using cli

Manging your Amazon Web Services via the command line utility can be very helpful. Specially in case you are writting some scripts.

You can get the details about the usage and installation for the AWS CLI at “AWS Command Line Interface doc“.

AWS Auto Scaling – Add or Remove availability zone from a region using cli

In this article I will provide you the command/syntax to be used to add or remove availability zone from a region using cli while using Auto Scaling.

Auto Scaling provides the ability to scale up or scale down the capacity for Amazon EC2. It increases or decreases the EC2 instance seamlessly during rise or fall in the demand. An efficient method to manage costs while using AWS.

AWS Auto Scaling – Add or Remove availability zone from a region using cli

Each region for Amazon has several different availability zones. Based on the requirement and scaling needs we can choose which availability zones to be used to spin up the additional instances.

In this example let’s consider adding an availability zone us-east-1e from the region us-east-1. The Auto Scaling group we will be modifying here is gagan-web-server.

Let’s just list the currently available availability zones in this Auto Scaling group.

The syntax is:

as-describe-auto-scaling-groups –region

In my case I used:

[[email protected] ~]# as-describe-auto-scaling-groups gagan-web-server –region us-east-1

Output:

AUTO-SCALING-GROUP  gagan-web-server  gagan-web-service-1  us-east-1c,us-east-1a,us-east-1b,us-east-1d  gagan-lb-1  5  10  5
INSTANCE  i-xxxxxxxx  us-east-1c  InService  Healthy  gagan-web-service-1
INSTANCE  i-xxxxxxxx  us-east-1a  InService  Healthy  gagan-web-service-1
INSTANCE  i-xxxxxxxx  us-east-1b  InService  Healthy  gagan-web-service-1
INSTANCE  i-xxxxxxxx  us-east-1d  InService  Healthy  gagan-web-service-1
INSTANCE  i-xxxxxxxx  us-east-1c  InService  Healthy  gagan-web-service-1
TAG  gagan-web-server  auto-scaling-group  Name          gagan-web-server  true
TAG  gagan-web-server  auto-scaling-group  Purpose       web-service       true

AWS Auto Scaling – Add or Remove availability zone from a region using cli

Now let’s add the availability zone us-east-1e from the region us-east-1 to this Auto Scaling group.

The syntax is:

as-update-auto-scaling-group –region –availability-zones value1,value2,value3..

To add the above availability zone to the existing ones, I used:

[[email protected] ~]# as-update-auto-scaling-group gagan-web-server –region us-east-1 –availability-zones us-east-1a,us-east-1b,us-east-1c,us-east-1d,us-east-1e

Output:

[[email protected] ~]# as-update-auto-scaling-group gagan-web-server --region us-east-1 --availability-zones us-east-1a,us-east-1b,us-east-1c,us-east-1d,us-east-1e
OK-Updated AutoScalingGroup

Verify the status and availability zones again using as-describe-auto-scaling-groups.

In order to remove an availability zone, you simply have to take the list of existing availability zones (using as-describe-auto-scaling-groups). Remove the one you don’t want and update the Auto Scaling group using as-update-auto-scaling-group.

AWS Auto Scaling – Add or Remove availability zone from a region using cli

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.