You can do the following:

In the navigation pane, choose Instances. In the top right corner, choose the Show/Hide icon, and then select Lifecycle. For each instance, Lifecycle is either normal, spot, or scheduled.

Alternatively run this CLI command aws ec2 describe-spot-instance-requests \ --query "SpotInstanceRequests[*].{ID:InstanceId}"

Source: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html#using-spot-instances-running

Answer from Chris Williams on Stack Overflow
🌐
Amazon Web Services
docs.aws.amazon.com › amazon ec2 › user guide › amazon ec2 instances › amazon ec2 billing and purchasing options › spot instances › get the status of a spot instance request
Get the status of a Spot Instance request - Amazon Elastic Compute Cloud
... You can get status information for your Spot Instance request. ... In the navigation pane, choose Spot Requests and select the Spot request. To check the status, on the Description tab, check the Status field. ... Use the following describe-spot-instance-requests command. aws ec2 ...
🌐
Amazon Web Services
docs.aws.amazon.com › amazon ec2 › user guide › amazon ec2 instances › amazon ec2 billing and purchasing options › spot instances › spot instance interruptions › find interrupted spot instances
Find interrupted Spot Instances - AWS Documentation
If the interruption behavior is to stop the Spot Instances, use the following example: aws ec2 describe-instances \ --filters Name=instance-lifecycle,Values=spot \ Name=instance-state-name,Values=stopped \ Name=state-reason-code,Values=Server.SpotInstanceShutdown \ --query "Reservations[*].Instances[*].InstanceId"
🌐
AWS
aws.amazon.com › ec2 › ec2 spot › instance advisor
Amazon EC2 Spot Instances - AWS
1 week ago - While the average frequency of interruption across all Regions and Instance types has historically been <5%, the actual interruption rate for your workloads will depend on point-in-time available capacity. You can use Spot Placement Score to get a near real-time likelihood of your Spot request ...
🌐
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › ec2 › describe-spot-instance-requests.html
describe-spot-instance-requests — AWS CLI 2.32.11 Command Reference
Alternatively, you can use DescribeInstances with a filter to look for instances where the instance lifecycle is spot . We recommend that you set MaxResults to a value between 5 and 1000 to limit the number of items returned. This paginates the output, which makes the list more manageable and ...
🌐
Amazon Web Services
docs.aws.amazon.com › amazon ec2 › user guide › amazon ec2 instances › amazon ec2 billing and purchasing options › spot instances › manage your spot instances
Manage your Spot Instances - Amazon Elastic Compute Cloud
You can't stop a Spot Instance if it is part of a fleet or launch group, or Availability Zone group. ... In the navigation pane, choose Instances. Select the Spot Instance. If you didn't save the instance ID of the Spot Instance, see Find your Spot Instances.
Find elsewhere
Top answer
1 of 2
5

There is no public API to check Spot Instance availability. Having said that, you can still achieve what you want by following the below steps:

  1. Use request_spot_fleet instead, and configure it to launch a single instance.
  2. Be flexible with the instance types you use, pick as many as you can and include them in the request. To help you pick the instances, check Spot Instance advisor for instance interruption and saving rates.
  3. At the Spot Fleet request, configure AllocationStrategy to capacityOptimized this will allow the fleet to allocate capacity form the most available Spot instance from your instances list and reduce the likelihood of Spot interruptions.
  4. Don't set a max price SpotPrice, the default Spot instance price will be used. The pricing model for Spot has changed and it's no longer based on bidding, therefore Spot prices are more stable and don't fluctuate.
2 of 2
2

This may be a bit overkill for what you are looking for but with parts of the code you can find the spot price history for the last hour (this can be changed). It'll give you the instance type, AZ, and additional information. From there you can loop through the instance type to by AZ. If a spot instance doesn't come up in say 30 seconds try the next AZ.

And to Ahmed's point in his answer, this information can be used in the spot_fleet_request instead of looping through the AZs. If you pass the wrong AZ or subnet in the spot fleet request, it may pass the dryrun api call, but can still fail the real call. Just a heads up on that if you are using the dryrun parameter.

Here's the output of the code that follows:

In [740]: df_spot_instance_options
Out[740]:
    AvailabilityZone   InstanceType  SpotPrice  MemSize  vCPUs  CurrentGeneration Processor
0         us-east-1d        t3.nano      0.002      512      2               True  [x86_64]
1         us-east-1b        t3.nano      0.002      512      2               True  [x86_64]
2         us-east-1a        t3.nano      0.002      512      2               True  [x86_64]
3         us-east-1c        t3.nano      0.002      512      2               True  [x86_64]
4         us-east-1d       t3a.nano      0.002      512      2               True  [x86_64]
..               ...            ...        ...      ...    ...                ...       ...
995       us-east-1a    p2.16xlarge      4.320   749568     64               True  [x86_64]
996       us-east-1b    p2.16xlarge      4.320   749568     64               True  [x86_64]
997       us-east-1c    p2.16xlarge      4.320   749568     64               True  [x86_64]
998       us-east-1d    p2.16xlarge     14.400   749568     64               True  [x86_64]
999       us-east-1c  p3dn.24xlarge      9.540   786432     96               True  [x86_64]

[1000 rows x 7 columns]

And here's the code:

import boto3
import pandas as pd
from datetime import datetime, timedelta

ec2c = boto3.client('ec2')
ec2r = boto3.resource('ec2')

#### The rest of this code maps the instance details to spot price in case you are looking for certain memory or cpu
paginator = ec2c.get_paginator('describe_instance_types')
response_iterator = paginator.paginate( )

df_hold_list = []
for page in response_iterator:
    df_hold_list.append(pd.DataFrame(page['InstanceTypes']))

df_instance_specs = pd.concat(df_hold_list, axis=0).reset_index(drop=True)
df_instance_specs['Spot'] = df_instance_specs['SupportedUsageClasses'].apply(lambda x: 1 if 'spot' in x else 0)
df_instance_spot_specs = df_instance_specs.loc[df_instance_specs['Spot']==1].reset_index(drop=True)

#unapck memory and cpu dictionaries
df_instance_spot_specs['MemSize'] = df_instance_spot_specs['MemoryInfo'].apply(lambda x: x.get('SizeInMiB'))
df_instance_spot_specs['vCPUs'] = df_instance_spot_specs['VCpuInfo'].apply(lambda x: x.get('DefaultVCpus'))
df_instance_spot_specs['Processor'] = df_instance_spot_specs['ProcessorInfo'].apply(lambda x: x.get('SupportedArchitectures'))

#look at instances only between 30MB and 70MB
instance_list = df_instance_spot_specs['InstanceType'].unique().tolist()

#---------------------------------------------------------------------------------------------------------------------
# You can use this section by itself to get the instancce type and availability zone and loop through the instance you want
# just modify instance_list with one instance you want informatin for
#look only in us-east-1
client = boto3.client('ec2', region_name='us-east-1')
prices = client.describe_spot_price_history(
    InstanceTypes=instance_list,
    ProductDescriptions=['Linux/UNIX', 'Linux/UNIX (Amazon VPC)'],
    StartTime=(datetime.now() -
               timedelta(hours=1)).isoformat(),
               # AvailabilityZone='us-east-1a'
    MaxResults=1000)

df_spot_prices = pd.DataFrame(prices['SpotPriceHistory'])
df_spot_prices['SpotPrice'] = df_spot_prices['SpotPrice'].astype('float')
df_spot_prices.sort_values('SpotPrice', inplace=True)
#---------------------------------------------------------------------------------------------------------------------

# merge memory size and cpu information into this dataframe
df_spot_instance_options = df_spot_prices[['AvailabilityZone', 'InstanceType', 'SpotPrice']].merge(df_instance_spot_specs[['InstanceType', 'MemSize', 'vCPUs',
                                            'CurrentGeneration', 'Processor']], left_on='InstanceType', right_on='InstanceType')
🌐
Reddit
reddit.com › r/aws › spot instances, capacity not available, how to debug?
r/aws on Reddit: Spot instances, capacity not available, how to debug?
December 6, 2022 -

Hi.

I'm having a hard time starting up m5a.xlarge spot instances because of capacity.

capacity-not-available

Max bid price is $0.120, and this link (https://aws.amazon.com/ec2/spot/pricing/) says the current price is $0.10 for useast (north virginia) so why I have no capacity?

And here's the price history

Trying to figure out how to analyze this.

Thank you!

🌐
Spot.io
spot.io › resources › aws-ec2-pricing › what-are-ec2-spot-instances
What are AWS spot instances?
December 13, 2022 - How can you check spot Instance price history? To view spot price history: Open the Amazon EC2 console and click Spot Requests. Select Pricing history. Choose a product (operating system).
🌐
Amazon Web Services
amazonaws.cn › products › amazon ec2 › amazon ec2 spot
Amazon EC2 Spot Instances FAQs
1 week ago - The Amazon Web Services Management Console makes a detailed billing report available which shows Spot instance start and termination/stop times for all instances. Customers can check the billing report against historical Spot prices via the API to verify that the Spot price they were billed ...
🌐
Amazon Web Services
docs.aws.amazon.com › amazon ec2 › user guide › amazon ec2 instances › amazon ec2 billing and purchasing options › spot instances
Spot Instances - Amazon Elastic Compute Cloud
To view the Spot price history for the past three months, use the Amazon EC2 console or the describe-spot-price-history command. For more information, see View Spot Instance pricing history. We independently map Availability Zones to codes for each AWS account.
🌐
GitHub
github.com › alexei-led › spotinfo
GitHub - alexei-led/spotinfo: CLI for exploring AWS EC2 Spot inventory. Inspect AWS Spot instance types, saving, price, and interruption frequency.
CLI for exploring AWS EC2 Spot inventory. Inspect AWS Spot instance types, saving, price, and interruption frequency. - alexei-led/spotinfo
Starred by 156 users
Forked by 10 users
Languages   Go 97.7% | Makefile 1.8% | Dockerfile 0.5%
🌐
DoiT
doit.com › home › spotinfo  —  a new cli for aws spot
Spotinfo — a new CLI for AWS Spot | DoiT
November 19, 2022 - But to find out, what is the actual price, you are going to pay, you must visit a different AWS Spot pricing web page and search it again for the specific instance type. The spotinfo saves your time and can display the spot price alongside other information. You can also filter and sort by spot price if you like.
🌐
Amazon Web Services
docs.aws.amazon.com › amazon ec2 › user guide › amazon ec2 instances › amazon ec2 billing and purchasing options › spot instances › how spot instances work
How Spot Instances work - Amazon Elastic Compute Cloud
A one-time Spot Instance request remains active until Amazon EC2 launches the Spot Instance, the request expires, or you cancel the request. If capacity is not available, your Spot Instance is terminated and the Spot Instance request is closed.