Instantly share code, notes, and snippets.

Embed
What would you like to do?
Plot EC2 spot pricing with boto3 and pandas
import pandas as pd
from boto3 import client
client = client(service_name='ec2')
prices = client.describe_spot_price_history(InstanceTypes=["m3.medium"],
AvailabilityZone="us-east-1a")
df = pd.DataFrame(prices['SpotPriceHistory'])
df.set_index("Timestamp", inplace=True)
df["SpotPrice"] = df.SpotPrice.astype(float)
df = df.sort_index()
week_ago = pd.datetime.now() - pd.datetools.Day(7)
twice_daily = df.ix[week_ago:].resample("12h")
twice_daily.SpotPrice.plot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment