Choosing the right Amazon EC2 Spot Instances for your workloads

The main issue was narrowing down the enormous list of instance types so they would be suitable to run our workloads.

Choosing the right Amazon EC2 Spot Instances for your workloads

On a recent project we were looking to take advantage of Amazon EC2 spot instances. The main issue was narrowing down the enormous list of instance types so they would be suitable to run our workloads. There are so many instance types with AWS, and they are growing all the time. To compound the problems, not all instance types are in every region.

Our key requirements were:

  • 8 vCPU
  • 32 GB RAM
  • 58 pods per node (we use the nodes in EKS)
  • Available in Sydney (ap-southeast-2)

Rather than go through manually all the instances to ensure they meet the above minimum requirements (to which there are 565 instance types 😲) to find the most optimal instances, I thought there must be a better way (read: faster).

Introducing Amazon EC2 Instance Selector

This is a neat little CLI tool that seems like is a great fit for this exact problem.

GitHub - aws/amazon-ec2-instance-selector: A CLI tool and go library which recommends instance types based on resource criteria like vcpus and memory
A CLI tool and go library which recommends instance types based on resource criteria like vcpus and memory - GitHub - aws/amazon-ec2-instance-selector: A CLI tool and go library which recommends in...

Installation is simple on a mac:

brew tap aws/tap
brew install ec2-instance-selector
Install Amazon EC2 Instance Selector on a Mac

Here is the command that I ended up using to select the instances. Of note, I am asking for:

  • 8 vCPU exactly and 32 GB RAM exactly. This seems to always yield 58 pods/node density when run in EKS. This is desirable for us.
  • Current generation instances only
  • Available in Sydney
  • Must be spot capable
  • No GPU instances, we don't have a use for these, and they cost loads
  • Deny the t series (not suitable for our workloads), deny the i series (not suitable for our workloads), deny the r series (not suitable for our workloads)
  • x86 architecture (perhaps ARM in the future)
  • No more than 30 cents an hour
ec2-instance-selector \
  --profile $PROFILE_NAME \
  --vcpus 8 \
  --memory-min 32 \
  --current-generation true \
  --region ap-southeast-2 \
  --usage-class spot \
  --gpus 0 \
  --max-results 50 \
  --deny-list '^(t|i|r)' \
  --cpu-architecture x86_64 \
  --price-per-hour-max 0.3 \
  --output table-wide
The full ec2-instance-selector command that we ended up using

This yields the following table:

table-wide output for the ec2-instance-selector

Changing the output format to one-line for easy copy/paste.

m4.2xlarge,m5.2xlarge,m5a.2xlarge,m5ad.2xlarge,m5d.2xlarge,m5zn.2xlarge,m6i.2xlarge

And there you have it, this is how we were able to filter the giant list of AWS instance types to just 7.

I hope this ends up helping someone else in the future.