Skill Level: Any Skill Level


  1. What is AWS Spot Instance?

    Amazon Web Services (AWS) provides spot instances, a purchasing option that allows you to buy unused Amazon EC2 capacity at significant discounts. Spot instances are a flexible way to obtain extra capacity on Amazon. 

    In the spot instance model, you receive compute instances through a bidding process, in which you specify the hourly price you are prepared to pay. You bid your price, and when an EC2 instance is offered at that price, the instance is launched. If the spot price rises and exceeds your bid, the instance is terminated. When the price drops again, the instances are reactivated.

  2. When to Use Spot Instances?

    Spot instances are most suitable for applications that have fault tolerance built in, are stateless, or perform data processing in large clusters (for example, Hadoop). They can also be used for applications that regularly save data to persistent storage such as S3 or EFS, or can be used to extend existing applications running on regular on-demand instances.

    Additional use cases include:

    • Batch processing—you can use the AWS Batch service in combination with spot instances to run batch processing on spot instances that are currently available at a low cost. This can generate significant cost savings compared to running the same batch process using on-demand instances.
    • Continuous integration—development and testing is very common in a cloud environment. Dev/test tasks typically run on an irregular schedule, and because they are not production workloads, they can tolerate occasional interruptions.
    • High performance computing (HPC)—you can use spot instances to run massively parallel workloads like artificial intelligence analytics applications. These applications run on graphical processing units (GPUs), and since GPU instances are expensive, spot instances can be a big help.

  3. 5 Best Practices for AWS Spot Instances

    The following best practices can help you make more effective use of spot instances on AWS.

    1. Be Flexible About Instance Types and Availability Zones

    Try to be flexible when requesting an instance type and availability zone (AZ) in which your workloads can be deployed. This gives the spot instance mechanism more opportunities to find and allocate your required capacity at the required cost.

    Keep in mind that AWS defines a spot instance pool as a group of available spot instances which all have the same instance type, in the same availability zone. Opening yourself to more instance types, and more availability zones, will allow you to draw from additional spot instance pools. 

    If workloads can be scaled vertically, a larger instance type (more vCPUs and memory) should be a good option. 
    If the workload can scale horizontally, provide the option of smaller or older generation instances, because you can scale out the application to these instances to use their capacity. Older generation instances are more likely to be available as spot instances because their demand is weaker.

    Amazon recommends including at least 10 instance types in each spot instance request. Configure your virtual private cloud (VPC) to support all AZs in your region, to make sure you can use spot instances from any availability zone.

    2. Prepare Workloads Running on Spot Instances for Interruptions

    A spot instance can be interrupted with two minutes’ notice. A new feature from EC2 is an instance rebalancing recommendation—this is an early warning that a spot instance may be interrupted. You will sometimes (but not always) receive this warning and will have more time to migrate your workloads to other instances.

    When you receive a rebalancing recommendation, or a spot instance termination notice, you’ll need to have a way to quickly move applications to another instance. It is advised to design your application for fault tolerance—this way you will improve availability and resilience, and also be able to easily handle the termination of spot instances.

    3. Use EC2 Auto Scaling Groups or Spot Fleet

    You can use Auto Scaling Groups, or the AWS Spot Fleet feature, to define a certain number of instances, or a specific quantity of vCPUs or memory you need for your workloads. The Auto Scaling group can then automatically add capacity from available spot instances, according to your settings. When a spot instance is terminated, it can automatically find additional spot instances that meet your criteria and launch them instead. Auto Scaling Groups now support mixing both on-demand and spot instances, for greater reliability.

    4. Use Auto Scaling for Rebalancing

    Auto Scaling Groups support the new rebalancing warning EC2 provides in advance of termination of a spot instance. Auto Scaling can automatically replace spot instances as soon as a rebalancing warning is received.

    5. Use Integrated AWS Services to Manage Your Spot Instances

    There are several AWS services that can help you manage spot instances. For example:

    • Amazon EMR—can run distributed map/reduce jobs on spot instances
    • Amazon ECS—can run containers on your spot instances
    • AWS Batch—can run distributed batch jobs
    • AWS Elastic Beanstalk—can deploy web applications on spot instances

  4. Conclusion

    In this article I explained how AWS spot instances work, which cloud workloads they are most suitable for, and provided five ways you can use spot instances more effectively:

    • Allowing flexible use of instance types and availability zones
    • Preparing for interruption of spot instances
    • Using Auto Scaling to automatically add spot instance capacity
    • Using Auto Scaling to rebalance instances when they are terminated
    • Managing and utilizing spot instances using other AWS services


    I hope this will be helpful in your adoption of spot instances, which can help you save up to 90% of computing costs on AWS.

Join The Discussion