Skip to content

Instantly share code, notes, and snippets.

@jseabold
Created August 11, 2015 14:33
Show Gist options
  • Save jseabold/9004454ac4140845f1de to your computer and use it in GitHub Desktop.
Save jseabold/9004454ac4140845f1de to your computer and use it in GitHub Desktop.
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