Which AWS Regions Have Spot Instances? Type, Cost, Zone, Interrupt Rate & Region Availability Report.
Tags: aws, devops, cloud
Published: 2021-08-02 20:42:51

AWS offers several alternatives for selecting an EC2 Instance. You can choose between On-Demand, Reserved, and Spot. This post focuses mainly on the spot instance.  A spot instance takes advantage of unused EC2 capacity at a lower price than the On-Demand fee.  

So, how can you determine the current cost of a spot instance? Also, in which region and availability zone are spot instances available? And what about interrupt rate?  You don't want to browse the AWS spot instance [price page](https://aws.amazon.com/ec2/spot/pricing/) every time this information is needed or updated.

To assist in answering these and other questions, I developed a Python script. I hope it might help others as well. It can assist you in answering some of the questions listed below.  

### Which AvailabilityZone Has What Spot Instance Type?
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgx4tj5dt9wzzge5vkz1.png)

### What is the Spot Instance Type Cost In The AvailabilityZone?
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20ak9l18tcn677a8t0re.png)

### Instance Types And Product Description
For a particular instance type, how many availability zones contain the following product descriptions.
* Linux/UNIX
* Windows
* Linux/UNIX (Amazon VPC)
* Windows (Amazon VPC)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45309syompdis5jdiv4d.png)

### Availability Zone And Product Description
For a particular availability zone, how many instant types contain the following product descriptions.
* Linux/UNIX
* Windows
* Linux/UNIX (Amazon VPC)
* Windows (Amazon VPC)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wt5bfddczs4kpdafo5d0.png)

### Price By Availability Zone, Instance Type And Region
Display spot pricing by instance type, availability zone and region.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3o3o8sdaftoibz63n4j.png)

### Interrupt Rate By Region, Instance Type And OS
Display interrupt rate by region, availability zone and OS.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbmo2ng7mwkkg76lmjcj.png)

Download the script from [github](https://github.com/hseera/aws-python-utilities/blob/main/visualize_ec2_spot_instance_info.py).  For testing purpose, the script only queries spot information for the instance types "t3a.small", "t3a.2xlarge", "c5a.large" and "m4.xlarge". Replace them with your instance types, or you can get spot data for all instance types. To obtain information for all instance types, uncomment the code in the script.

The script not only generates the visualization but also saves the data to a CSV file. CSV data can be analyzed further using various visualization tools. The script can be enhanced to save the data in a database instead of CSV.

If you have any recommendations for how to enhance this script further, please contact me or leave a comment in the comments section. 

------------------------------------------------------------------

Thanks for reading!

If you enjoyed this article feel free to share it on social media 🙂


Say Hello on: [Linkedin](https://www.linkedin.com/in/harinderseera/) | [Twitter](https://twitter.com/harinderseera) | [Polywork](https://www.polywork.com/harinderseera) 

Blogging: [Dev](https://dev.to/harinderseera) | [Hashnode](https://harinderseera.hashnode.dev/)

Github: [hseera](https://github.com/hseera)