How to Use AWS Cloud Auto Scaling to Launch Spot EC2 Instances

AutoscalingAWS Auto Scaling provides horizontal scaling by automatically adding or removing compute resources for the application hosted on AWS. Auto Scaling is ideally suited for applications where there is a requirement for scalability.

Do you Auto-Scale your AWS Cloud?

In addition, it is also very important to track the cost of the AWS resources since AWS charges as per the pay as you go model. AWS provides three kinds of instances: On-demandReserved Instances andSpot Instances.

For the spot instance, the user can bid for the unused AWS EC2 compute power at a cheaper rate. The spot instance helps the user to save some costs as the price bid is normally lesser than the on-demand fixed price. To use a spot instance, it requires placing a bid for the maximum amount that the user is ready to pay. If the current spot price is lesser than the bid price, AWS allows the user to launch a spot instance, whereby it will be charged at the current spot price. When the spot instance price is higher than the maximum bid price, AWS will terminate the instance.

Spot instances gives very good flexibility as Auto scaling launches new instances on certain conditions and terminates them when not required. Using a spot instance helps the user to add additional compute power at a lower rate.

The present guide demonstrates how to launch spot instances with Auto Scaling. Since AWS does not provide the management console for Auto Scaling, all the tasks would be performed by CLI.

 

1. Download and install the Auto Scaling CLI.

2. Create new a launch configuration.

The user can specify the security group and the key-pair name in launch configuration with the below mentioned command:

as-create-launch-config <Config Name> --image-id <Image ID> --region <Region> --instance-type <Instance Type> --key <Key-Pair Name> --group <Security Group Name> --spot-price "<The Maximum Amount user is ready to pay>"

 

 

In the above mentioned command, the spot-price is the maximum price that the user is ready to pay and not the price that the user will be charged. AWS will charge the user as per the current spot price only. AWS will run the instances until the above specified spot price is less than the actual AWS instance spot price.

3. Create a new Auto Scaling group.

Run the following command:

as-create-auto-scaling-group <Group Name> --launch-configuration <Launch Config Name> --region <Region Name> --availability-zones <Availability Zone> --min-size <Min Size> --max-size <max Size>

 

 

4. Check the scaling activities with the following command:

as-describe-scaling-activities --auto-scaling-group <Auto Scaling Group Name> --headers --region us-west-2

 

 

The scaling activity shows that Auto Scaling has requested for two spot instances. When the request is confirmed the instances will be launched.

5. The user can view the spot instances from the AWS console.

 

 

6. Check the Auto Scaling group configuration and instances either with the following command:

as-describe-auto-scaling-groups <Auto Scaling Group Name> --headers --region us-west-2

or with the below mentioned command:

as-describe-auto-scaling-instances --headers --region us-west-2

 

 

7. The above mentioned command shows both the running spot instances.

Keywords: Amazon web services, Amazon AWS console, Amazon AWS instances, EC2 Service, Amazon cloud computing, CLI tools, AWS Auto Scaling, AWS Automation, AWS Configuration, AWS Instance Type, Cloud Scalablity, Spot Instances

Advertisements
Leave a comment

Leave your opinion

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: