You've successfully subscribed to MyPad Blog
Great! Next, complete checkout for full access to MyPad Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

AWS EC2 spot price history using Python and boto3

AWS EC2 spot price history using Python and boto3

We are working on a project to optimize EC2 costs for few deep learning EC2 instances.

Getting the price data for the EC2 spots is a key data point of the analysis. The below script does the job pretty well.

import sys
import boto3
import json
import pandas as pd
import math

client = boto3.client('ec2')
response = client.describe_spot_price_history()

df = pd.DataFrame(response['SpotPriceHistory'])
df = df[df.apply(lambda x: not(math.isnan(float(x['SpotPrice']))), axis=1)]
df['Monthly'] = df['SpotPrice'].astype(float) * 31 * 24