Explore AWS spot Instances from the command line
TL;DR
The spotinfo
is a command-line tool you can use for exploring AWS Spot instances across multiple AWS regions.
Introduction
Using Amazon EC2 Spot instances is an excellent way to reduce EC2 on-demand instance cost, up to 90%. Whenever you have a workload that can survive VM interruption or be suspended and resumed later on without impacting business use cases, choosing the Spot pricing model is a no-brainer choice.
The lower your interruption rate, the longer your Spot instances are likely to run.
Amazon provides an excellent web interface AWS Spot Instance Advisor to explore available Spot instances and determine spot instance pools with the least chance of interruption. You can also check the savings you get over on-demand rates. You can also check the savings you get over on-demand rates. And then, you are supposed to use these metrics for selecting appropriate Spot instances.
While the AWS Spot Instance Advisor is a valuable tool, it is not easy to use its data for scripting and automation, and some use cases require too many clicks.
Spotinfo tool
That’s why I created the spotinfo
tool. It's an easy-to-use command-line tool (open source under Apache 2.0 License) that allows you to explore AWS Spot instances in a terminal and use the spot data it provides for scripting and automation.
Under the hood, the spotinfo
is using two public data sources available from AWS:
Features
The spotinfo
allows you to access the same information you can see in the AWS Spot Instance Advisor, but from a command line and can be used for scripting and automation use cases. In addition, the tool provides some useful features that are not available for the AWS Spot Instance Advisor web interface.
Advanced Filtering
The first feature is advanced filtering. You can filter spot instances by:
- vCPU — minimum number of CPU cores
- Memory GiB — minimum memory size
- Operating system — Linux or Windows
- Region — one or more AWS regions (or
all
AWS regions) - Savings (compared to on-demand)
- Frequency of interruption
- Hourly rate (in
USD/hour
)
When filtering by instance type, regular expressions are supported. And this can help you create advanced queries.
Example: filter with Regex
List (as text) all available EC2 Spot instances powered by Graviton2 processor, with a minimum of eight CPU cores, in the us-west-2
(Oregon) region, sorting results by spot price.
Spot Price Visibility
With AWS Spot Instance Advisor, you can see a discount compared to the on-demand EC2 instance rate. But to find out, what is the actual price, you are going to pay, you must visit a different AWS Spot pricing web page and search it again for the specific instance type.
The spotinfo
saves your time and can display the spot price alongside other information. You can also filter and sort by spot price if you like.
Flexible Output Formats
Working with data in a command line and accessing data from scripts and automation requires flexibility of output format. The spotinfo
can return results in multiple formats: human-friendly formats, like table
and plain text
, and automation-friendly: json
, csv
, or just a saving number. Choose whatever format you need for any concrete use case.
Compare Spots across multiple Regions
One annoying thing about the AWS Spot Instance Advisor is the inability to compare EC2 spot instances across multiple AWS regions. Only a single region view is available, or you need to open multiple browser tabs and constantly switch between them to compare spot instances across multiple AWS regions.
The spotinfo
can help you to compare spot instances across multiple AWS regions. All you need to do is pass a --region
command-line flag, and you can use this flag more than once.
Another option is to pass a special all
value (with --region=all
flag) to see spot instances across all available AWS regions.
Example: explore t4g.small
Spot instance
Explore the t4g.small
spot instance type availability and rate across all AWS regions, where this instance type is available.
Network Resilience
While the spotinfo
uses public AWS data feeds, it also embeds the same data within the tool. So, if the data feed is not available, for any reason (no connectivity, service not available or other), the spotinfo
still will be able to return the same result.
Summary
I hope the spotinfo
could be a helpful tool for exploring AWS EC2 spot instances. And I'm looking forward to your comments and any questions you might have.
I invite you to contribute (issues, features, pull requests) to the alexei-led/spotinfo GitHub project.
p.s.: if you like the spotinfo
tool, consider giving the GitHub project a ⭐️
Thanks for reading! To stay connected, follow us on the DoiT Engineering Blog, DoiT Linkedin Channel, and DoiT Twitter Channel. To explore career opportunities, visit https://careers.doit.com.