Skip to content

Instantly share code, notes, and snippets.

@pataiji
Last active January 26, 2017 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pataiji/6b94c2f5c209738fbf38c0b2167025a2 to your computer and use it in GitHub Desktop.
Save pataiji/6b94c2f5c209738fbf38c0b2167025a2 to your computer and use it in GitHub Desktop.
Get Amazon EC2 spot instances pricing summary

Requirements

  • R
  • awscli

Usage

[pataiji@mbp ~]$ spot-price -t m4.large -s '2017-01-01'
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
0.02180 0.02540 0.03230 0.03375 0.03990 0.10000
#!/bin/sh
echo_help() {
echo "usage: spot-price -t instance-types -s start-time [-e end-time] [-p profile] [-r region]" 1>&2
exit 1
}
main_args=''
sub_args="--product-descriptions 'Linux/UNIX'"
while getopts p:t:s:e:r: opts
do
case "$opts" in
p)
main_args="$main_args --profile '$OPTARG'"
;;
r)
main_args="$main_args --region '$OPTARG'"
;;
t)
sub_args="$sub_args --instance-types '$OPTARG'"
;;
s)
sub_args="$sub_args --start-time '$OPTARG'"
;;
e)
sub_args="$sub_args --end-time '$OPTARG'"
;;
*)
echo_help
;;
esac
done
shift $((OPTIND - 1))
(echo "$sub_args" | grep -q -- --instance-types && echo "$sub_args" | grep -q -- --start-time) || echo_help
cmd="aws ${main_args} ec2 describe-spot-price-history ${sub_args}"
eval "$cmd" | jq '.SpotPriceHistory[].SpotPrice' | sed 's/"//g' | summary
#!/usr/bin/env Rscript
# http://unix.stackexchange.com/questions/13731/is-there-a-way-to-get-the-min-max-median-and-average-of-a-list-of-numbers-in
d<-scan("stdin", quiet=TRUE)
summary(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment