Skip to content

Instantly share code, notes, and snippets.

@nijave
Created July 3, 2019 17:34
Show Gist options
  • Save nijave/00598e83268583344a2660b02c41aa4c to your computer and use it in GitHub Desktop.
Save nijave/00598e83268583344a2660b02c41aa4c to your computer and use it in GitHub Desktop.
Spot instance request counts
import pandas as pd
from pandas.io.json import json_normalize
import json
import boto3
client = boto3.client('ec2')
data = client.describe_spot_instance_requests()
df = pd.DataFrame(json_normalize(data['SpotInstanceRequests'])).set_index('InstanceId')
df['RequestFailed'] = df['Status.Message'].apply(lambda x: str("unused capacity" in x))
df['InstanceType'] = df['LaunchSpecification.InstanceType']
df['Message'] = df['Status.Message']
df2 = df[ ['InstanceType', 'Message', 'RequestFailed'] ]
print(pd.pivot_table(df2, columns='RequestFailed', index=['InstanceType'], aggfunc='count'))
@nijave
Copy link
Author

nijave commented Jul 3, 2019

This dumps count of successful and failed spot instance requests grouped by instance type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment