Created
July 3, 2019 17:34
-
-
Save nijave/00598e83268583344a2660b02c41aa4c to your computer and use it in GitHub Desktop.
Spot instance request counts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This dumps count of successful and failed spot instance requests grouped by instance type