Skip to main content

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

https://pypi.org/project/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'}, ...]
'''

Metadata

Release files for amazon-ec2-best-instance 3.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amazon-ec2-best-instance 3.0.3
File Size Uploaded
amazon_ec2_best_instance-3.0.3.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for amazon-ec2-best-instance 3.0.3
File Interpreter ABI Platform
amazon_ec2_best_instance-3.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / amazon_ec2_best_instance-3.0.3.tar.gz

Download URL amazon_ec2_best_instance-3.0.3.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f1cc4b6fed78eb59f0608a44fc07afab6d5ea302cf8e025e4cb440791fe781c6
BLAKE2b-256 checksum
How to use checksums
838338fd03b9ca0816a4cdc5ee4367483b9c909cdaf9537cb35a03abf7270ff7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release files / amazon_ec2_best_instance-3.0.3-py3-none-any.whl

Download URL amazon_ec2_best_instance-3.0.3-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13a523111d8e01a1bc512a8eead23ba850931f45a5efb62b79730f7455b256f0
BLAKE2b-256 checksum
How to use checksums
509cb504138b52bd1d35518e12722aa478bb66b4dcafd7d8f0201f4b5b836967
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

3.0.3 This release

2 release files

3.0.2

1 release file

3.0.1

2 release files

3.0.0

2 release files

2.5.0

2 release files

2.4.3

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page