Amazon EC2 Best Instance (amazon-ec2-best-instance) allows you to choose the most optimal and cheap EC2 instance type for on-demand and spot and with a less reclaimed rate for a spot instance.
Project description
Amazon EC2 Best Instance (amazon-ec2-best-instance)
Amazon EC2 Best Instance (amazon-ec2-best-instance) allows you to choose the most optimal and cheap EC2 instance type for on-demand and spot and with a less reclaimed rate for a spot instance.
Deprecation Notice
Important: This package is deprecated and should no longer be used. Please switch to the 'best-ec2' package by running:
pip install best-ec2
Prerequisites
- python3
- pip3
- boto3
- AWS Account
- AWS Credentials
Install
pip install amazon-ec2-best-instance
Options
- vcpu Required. Float. Describes the vCPU configurations for the instance type.
- memory_gb Required. Float. Describes the memory for the instance type in GiB.
- usage_class Optional. String. Indicates whether the instance type is offered for spot or On-Demand. Default: 'on-demand'. Values: 'spot'|'on-demand'.
- burstable Optional. Boolean. Indicates whether the instance type is a burstable performance instance type.
- architecture Optional. String. The architectures supported by the instance type. Default: 'x86_64'. Values: 'i386'|'x86_64'|'arm64'|'x86_64_mac'
- product_descriptions Optional. List. The operating system that you will use on the virtual machine. Default: ['Linux/UNIX']. Values: Linux/UNIX | Red Hat Enterprise Linux | SUSE Linux | Windows | Linux/UNIX (Amazon VPC) | Red Hat Enterprise Linux (Amazon VPC) | SUSE Linux (Amazon VPC) | Windows (Amazon VPC)
- is_current_generation Optional. Boolean. Use the latest generation or not.
- has_gpu Optional. Boolean. Indicating whether the instance is equipped with a GPU. Default: None
- gpu_memory Optional. Integer. Amount of GPU Memory in Gigabytes (GiB). Only activated when 'has_gpu' is set to True. Default: None
- is_instance_storage_supported Optional. Boolean. Use instance types with instance store support
- max_interruption_frequency Optional. Integer (%). Max spot instance frequency interruption in percent. Note: If you specify >=21, then the '>20%' rate is applied. It is used only if 'usage_class' == 'spot' and 'is_best_price' == True
- availability_zones Optional. List. Availability zones. E.g. ['us-east-1a', 'us-east-1b']
- final_spot_price_determination_strategy Optional. String. Default: "min". Valid values: "min"|"max"|"average"
Usage
Simple
from amazon_ec2_best_instance import Ec2BestInstance
ec2_best_instance = Ec2BestInstance()
# It returns all available instance types, including those with over-provisioning resources (CPU, memory, etc.).
response = ec2_best_instance.get_best_instance_types({
'vcpu': 1,
'memory_gb': 2
})
print(response)
'''
[{'instance_type': 'c5n.2xlarge'}, ... , {'instance_type': 'x2iedn.8xlarge'}]
'''
Advanced
import boto3
from botocore.config import Config
import logging
from amazon_ec2_best_instance import Ec2BestInstance
ec2_client_config = Config(
retries={
'max_attempts': 20,
'mode': 'adaptive'
}
)
pricing_client_config = Config(
retries={
'max_attempts': 10,
'mode': 'standard'
}
)
ec2_client = boto3.Session().client('ec2', config=ec2_client_config)
pricing_client = boto3.Session().client('pricing', config=pricing_client_config)
# Optional.
options = {
# Optional. Default: us-east-1
'region': 'us-east-1',
# Optional. Default: 10
'describe_spot_price_history_concurrency': 20,
# Optional. Default: 10
'describe_on_demand_price_concurrency': 20,
'clients': {
'ec2': ec2_client,
'pricing': pricing_client
},
# Optional. Integer. Default: 120. It limits the lifetime of cache data.
'cache_ttl_in_minutes': 60
}
logging.basicConfig(level=logging.INFO, format='%(asctime)s: %(levelname)s: %(message)s')
# Optional.
logger = logging.getLogger()
ec2_best_instance = Ec2BestInstance(options, logger)
response = ec2_best_instance.get_best_instance_types({
# Required.
'vcpu': 1,
# Required.
'memory_gb': 2,
# Optional. Default: 'on-demand'. Values: 'spot'|'on-demand'
'usage_class': 'spot',
# Optional.
'burstable': False,
# Optional. Default: 'x86_64'. Values: 'i386'|'x86_64'|'arm64'|'x86_64_mac'
'architecture': 'x86_64',
# Optional. Default: ['Linux/UNIX'].
# Values: Linux/UNIX | Red Hat Enterprise Linux | SUSE Linux | Windows | Linux/UNIX (Amazon VPC) |
# Red Hat Enterprise Linux (Amazon VPC) | SUSE Linux (Amazon VPC) | Windows (Amazon VPC)
'product_descriptions': ['Linux/UNIX'],
# Optional.
'is_current_generation': True,
# Optional. If this parameter is set to True, the method will return the instance type with the best price.
'is_best_price': True,
# Optional. If this parameter is set to True, the method will return the instance type with the instance storage.
'is_instance_storage_supported': True,
# Optional. Integer. Max spot instance frequency interruption in percent.
'max_interruption_frequency': 10,
# Optional. List<String>. The availability zones.
'availability_zones': ['us-east-1a', 'us-east-1b']
})
print(response)
'''
[{'instance_type': 'c5d.large', 'price': '0.032700', 'interruption_frequency': {'min': 0, 'max': 5, 'rate': '<5%'}}, ...]
'''
Spot
If you need to get a spot instance with minimal price and minimal frequency of interruption you can use 'is_best_price' and/or 'max_interruption_frequency' input parameter
from amazon_ec2_best_instance import Ec2BestInstance
ec2_best_instance = Ec2BestInstance()
response = ec2_best_instance.get_best_instance_types({
# Required. Float
'vcpu': 31.2,
# Required. Float
'memory_gb': 100.5,
# Optional. String. Default: 'on-demand'. Values: 'spot'|'on-demand'
'usage_class': 'spot',
# Optional. Boolean.
# If this parameter is set to True, the method will return the instance type with the best price.
'is_best_price': True,
# Optional. Integer. Max spot instance frequency interruption in percent.
# Note: If you specify >=21, then the '>20%' rate is applied
# It is used only if 'usage_class' == 'spot' and 'is_best_price' == True
'max_interruption_frequency': 10
})
print(response)
'''
[{'instance_type': 'm6id.8xlarge', 'price': '0.642600', 'interruption_frequency': {'min': 6, 'max': 10, 'rate': '5-10%'}}, ...]
'''
from amazon_ec2_best_instance import Ec2BestInstance
ec2_best_instance = Ec2BestInstance()
response = ec2_best_instance.get_best_instance_types({
# Required. Float
'vcpu': 31.2,
# Required. Float
'memory_gb': 100.5,
# Optional. String. Default: 'on-demand'. Values: 'spot'|'on-demand'
'usage_class': 'spot',
# Optional. Boolean.
# If this parameter is set to True, the method will return the instance type with the best price.
'is_best_price': True
})
print(response)
'''
[{'instance_type': 'r5a.8xlarge', 'price': '0.578100'}, ...]
'''
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
File details
Details for the file amazon_ec2_best_instance-3.0.3.tar.gz
.
File metadata
- Download URL: amazon_ec2_best_instance-3.0.3.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1cc4b6fed78eb59f0608a44fc07afab6d5ea302cf8e025e4cb440791fe781c6 |
|
MD5 | 19bc244d95f1a9a19c36f04efd2363a5 |
|
BLAKE2b-256 | 838338fd03b9ca0816a4cdc5ee4367483b9c909cdaf9537cb35a03abf7270ff7 |
File details
Details for the file amazon_ec2_best_instance-3.0.3-py3-none-any.whl
.
File metadata
- Download URL: amazon_ec2_best_instance-3.0.3-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13a523111d8e01a1bc512a8eead23ba850931f45a5efb62b79730f7455b256f0 |
|
MD5 | da9c9d1bf66fc8bae8848bdcd96d5a18 |
|
BLAKE2b-256 | 509cb504138b52bd1d35518e12722aa478bb66b4dcafd7d8f0201f4b5b836967 |