Created
July 16, 2017 13:18
-
-
Save kafka399/f9b58c0082ac9ae6422e0b88ddada2fd to your computer and use it in GitHub Desktop.
R script to fetch spot prices from AWS
This file contains hidden or 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
#aws ec2 describe-spot-price-history --instance-types m4.xlarge --start-time 2017-05-16T01:08:09 --end-time 2017-07-16T12:09:10 --product-descriptions "Linux/UNIX" >dump.txt | |
require(jsonlite) | |
require(ggplot2) | |
require(dplyr) | |
prices = fromJSON('/projects/dump.txt') | |
prices = data.frame(prices$SpotPriceHistory) | |
prices$Timestamp = strptime(prices$Timestamp, '%Y-%m-%dT%H:%M:%S') | |
prices$Timestamp = as.POSIXct(prices$Timestamp) | |
prices$SpotPrice = as.numeric(prices$SpotPrice) | |
prices = prices%>%filter(AvailabilityZone !='us-east-1e') | |
prices$AvailabilityZone = factor(prices$AvailabilityZone) | |
ggplot(prices%>%filter(Timestamp>'2017-07-01'),aes(Timestamp,SpotPrice,color=AvailabilityZone))+ | |
geom_line(size=1.2)+ylim(0.065,0.085)+ theme_bw()+theme(axis.text.x = element_text(angle = 65, hjust = 1), | |
strip.text.x = element_text(size = 18),strip.text.y = element_text(size = 20), | |
axis.text=element_text(size=20),axis.title=element_text(size=20), | |
plot.title = element_text(size = 20),legend.text=element_text(size=20),legend.title=element_blank(), | |
axis.title.x=element_blank())+ labs(title = 'Spot prices of m4.xlarge on AWS, July 01-16, 2017') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment