AWS EC2 spot instance optimizer
Project description
Spot Optimizer
🚀 Spot Optimizer is a Python library that helps users select the best AWS spot instances based on their resource requirements, including cores, RAM, storage type (SSD), instance architecture (x86 or ARM), AWS region, EMR version compatibility, and instance family preferences.
It replaces complex, in-house logic for finding the best spot instances with a simple and powerful abstraction. No more manual guesswork — just the right instances at the right time.
Why Spot Optimizer?
Managing spot instance selection within your codebase can be tedious and error-prone. Spot Optimizer provides a clean, abstracted solution to intelligently select the most stable and cost-effective instances.
Configuration Guarantee
It ensures that the selected configuration meets or exceeds the user's requirements. For example, if you request 20 cores and 100GB of RAM, the library will suggest a configuration with at least those resources, rounding up to the nearest available configuration.
Key Benefits
- 💡 Informed Decisions: Picks instances with the lowest interruption rates and the best fit for your workload.
- 🧠 Dynamic Reliability: Smartly updates interruption rates every hour to ensure the most stable instance selection.
- 🛠️ Operational Efficiency: No more homegrown scripts or complex logic — just plug and play.
- ⚡ High Flexibility: Supports diverse use cases like Spark/EMR clusters, ML workloads, gaming servers, and more.
- 🏗️ Scalable and Reliable: Automatically adjusts to changing resource needs while minimizing downtime.
Installation
For Users
pip install spot-optimizer
For Development
# Clone the repository
git clone git@github.com:amarlearning/spot-optimizer.git
cd spot-optimizer
# Install dependencies and set up development environment
make install
Usage
API Usage
from spot_optimizer import optimize
# Basic usage
result = optimize(cores=8, memory=32)
# Advanced usage with all options
result = optimize(
cores=8,
memory=32,
region="us-east-1",
ssd_only=True,
arm_instances=False,
instance_family=["m6i", "r6i"],
mode="balanced"
)
print(result)
# Output:
# {
# "instances": {
# "type": "m6i.2xlarge",
# "count": 1
# },
# "mode": "balanced",
# "total_cores": 8,
# "total_ram": 32
# }
CLI Usage
# Basic usage
spot-optimizer optimize --cores 8 --memory 32
# Advanced usage
spot-optimizer optimize \
--cores 8 \
--memory 32 \
--region us-east-1 \
--ssd-only \
--no-arm \
--instance-family m6i r6i \
--mode balanced
# Get help
spot-optimizer --help
Inputs
Required Parameters
- cores (int): The total number of CPU cores required.
- memory (int): The total amount of memory required in GB.
Optional Parameters
- region (str): AWS region for spot instance selection (default: "us-west-2").
- ssd_only (bool): If
True, only suggest instances with SSD-backed storage (default: False). - arm_instances (bool): If
True, include ARM-based instances (default: True). - instance_family (List[str]): Filter by specific instance families (e.g., ['m6i', 'r6i']).
- emr_version (str): Optional EMR version to ensure instance compatibility.
- mode (str):
latency: Optimize for fewer, larger nodes (lower latency).fault_tolerance: Optimize for more, smaller nodes (better fault tolerance).balanced: Aim for a middle ground between fewer and more nodes.
Future Enhancements
- Cost Optimization:
- Include estimated instance costs and recommend the most cost-effective configuration.
- Support for Other Cloud Providers:
- Extend the library to support GCP and Azure instance types.
- Spot Interruption Rates:
- Include interruption rates in the selection criteria for spot instances.
Development
Make Commands
# Install dependencies
make install
# Run tests
make test
# Check test coverage
make coverage
# Clean up build artifacts
make clean
Performance Optimisations
- Efficiently updates the instance interruption table only every hour, avoiding unnecessary data fetches.
- Focuses on providing the most stable instances based on the latest interruption rate data.
Issues
If you encounter any bugs, please report them on the issue tracker. Alternatively, feel free to tweet me if you're having trouble. In fact, you should tweet me anyway.
License
Built with ♥ by Amar Prakash Pandey(@amarlearning) under Apache License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spot_optimizer-1.0.0.tar.gz.
File metadata
- Download URL: spot_optimizer-1.0.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.10.6 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
320de577f41f5e56d089ca204955fa8746eecde543773e8ddf36599fc98e0ce6
|
|
| MD5 |
ee79288a27b1af55055c229aa04d71cb
|
|
| BLAKE2b-256 |
c2ad78a74a285c9be9996e0281359d6837447bbef5ff29146bcd23f8a45fbedc
|
File details
Details for the file spot_optimizer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: spot_optimizer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.10.6 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4107f67090494cf1ec425b66476254623022d900f6e67a1d0fb413b101679e0
|
|
| MD5 |
62896676c92c2e14829f66ed716bb4d2
|
|
| BLAKE2b-256 |
2a92cb2c4f80159764820e4abe973c2c8389970bc5689f636a41455e161017d2
|