Amar Prakash Pandey - ᕦ(ò_óˇ)ᕤ

Spot Optimizer ≠ Spot Fleet: decide smart, then launch

banner

Picking EC2 Spot instances shouldn’t feel like rolling dice. Most teams either guess and get bitten by interruptions, or overbuild complicated logic to dodge them.

Here’s the clean split that keeps you sane:

Short version: Spot Optimizer decides what to run; EC2/Spot Fleet decide how to run it.


📦 Project Links

🔗 GitHub Repository — Source code, issues, and contributions
📋 PyPI Package — Install with pip install spot-optimizer


The Problem with Manual Spot Instance Selection

Manual spot instance selection typically involves:

This leads to over-provisioning, frequent interruptions, or both.


TL;DR


What Spot Optimizer Actually Does

Spot Optimizer abstracts away the complexity of spot instance selection.

Inputs

Guarantees

Outputs

Interfaces

Under the hood


Quick Start

Install

pip install spot-optimizer

API

from spot_optimizer import optimize

plan = optimize(
    cores=64,
    memory=256,
    region="us-east-1",
    ssd_only=True,
    arm_instances=False,
    instance_family=["m6i", "r6i"],
    mode="fault_tolerance",
)

print(plan)  # example: {"instances": {"type": "m6i.4xlarge", "count": 4}, "mode": "fault_tolerance", ...}

CLI

spot-optimizer \
  --cores 64 \
  --memory 256 \
  --region us-east-1 \
  --ssd-only \
  --no-arm \
  --instance-family m6i r6i \
  --mode fault_tolerance

Spot Optimizer vs EC2/Spot Fleet

Aspect Spot Optimizer EC2 Fleet / Spot Fleet
Purpose Decide instance types and counts Launch and maintain capacity
When to use When you’re deciding what to run When you’re launching and keeping it running
Output A shortlist of types + counts Actual EC2 instances
Focus Fit, stability, cost Capacity fulfillment, diversification

Why Pair Them


Integration with EC2 Fleet

Take Spot Optimizer’s output and pass it to LaunchTemplateConfigs[].Overrides.

import boto3
from spot_optimizer import optimize

def launch_optimized_fleet(cores: int, memory: int, region: str):
    # Get recommendations from Spot Optimizer
    plan = optimize(cores=cores, memory=memory, region=region, mode="fault_tolerance")
    itype = plan["instances"]["type"]
    count = plan["instances"]["count"]

    # Diversify across AZs; add sibling instance types if you want more pools
    overrides = [
        {"InstanceType": itype, "AvailabilityZone": f"{region}{az}"}
        for az in ("a", "b", "c")
    ]

    ec2 = boto3.client("ec2", region_name=region)

    resp = ec2.create_fleet(
        LaunchTemplateConfigs=[
            {
                "LaunchTemplateSpecification": {
                    "LaunchTemplateName": "my-workload-template",
                    "Version": "$Latest",
                },
                "Overrides": overrides,
            }
        ],
        TargetCapacitySpecification={
            "TotalTargetCapacity": count,
            "DefaultTargetCapacityType": "spot",
        },
        Type="maintain",  # keep capacity steady
        SpotOptions={
            "AllocationStrategy": "price-capacity-optimized",  # recommended
            "InstanceInterruptionBehavior": "terminate",
        },
    )

    return resp["FleetId"]

Best practices for EC2 Fleet integration


Integration with Spot Fleet

If you’re using the older Spot Fleet service, populate Launch Specifications/Overrides with the recommended instance types:

{
  "SpotFleetRequestConfig": {
    "IamFleetRole": "arn:aws:iam::<account>:role/aws-ec2-spot-fleet-role",
    "TargetCapacity": 8,
    "AllocationStrategy": "priceCapacityOptimized",
    "LaunchSpecifications": [
      {
        "ImageId": "ami-12345678",
        "InstanceType": "m6i.2xlarge",
        "SubnetId": "subnet-12345678"
      }
    ]
  }
}

When Spot Optimizer Makes a Difference

High‑impact scenarios

Lower‑impact scenarios (still good Spot candidates)

Choosing the right optimization mode

Tip: whichever you pick, pair it with capacity‑optimized in Fleet to land in deeper capacity pools.


Advanced Filtering Options

Filter by EMR version, choose ARM (Graviton) or x86, enforce SSD-only storage, and constrain by families like m6i/r6i. The goal: your shortlist is runnable and optimized, not just cheap.

Example with all filters

plan = optimize(
    cores=128,
    memory=512,
    region="us-west-2",
    ssd_only=True,           # Only SSD-backed instances
    arm_instances=True,      # Include ARM/Graviton instances
    instance_family=["m6i", "m6a", "r6i"],  # Specific families
    emr_version="6.4.0",     # EMR compatibility
    mode="balanced",
)

Performance & reliability

What this really means is fewer late‑night pages because a random pool went sideways.


Production Checklist

Before Deployment

  1. Generate candidates with Spot Optimizer (apply EMR/arch/storage/family filters and choose a mode)
  2. Test recommendations in a staging environment

Fleet Configuration

Ongoing Maintenance


FAQ

Is Spot Optimizer an alternative to Spot Fleet?

No. It’s complementary: Spot Optimizer chooses the right instances; EC2/Spot Fleet launches and manages them.

Can it run cross-region?

Yes—the library analyzes any region. Fleets themselves are region-bound, so you’ll need separate fleets per region.

Why not just pick the lowest-price instances?

Cheap pools can be fragile. Capacity-oriented strategies prefer deeper capacity pools to reduce interruptions, which often saves more money long-term.

How often should I refresh recommendations?

For production workloads, refresh daily or before major deployments. Interruption rates change as AWS capacity shifts.

Can I use this with Kubernetes/EKS?

Yes! Use Spot Optimizer to choose node instance types, then configure your node groups or Karpenter with those recommendations.

What about savings vs on-demand?

Spot instances typically save 50-90% vs on-demand. Spot Optimizer helps you get those savings without the interruption headaches.


References


Lastly, thank you for reading this post. For more awesome posts, you can explore my other articles here, and follow me on Github — amarlearning.

#aws #ec2 #spot-instances #cloud-computing #cost-optimization #infrastructure #devops #python #cli-tools

Comments