Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # request spot instance requests
  4.  
  5. require 'aws-sdk'
  6. require 'pry'
  7.  
  8. instance_type = ['m4.4xlarge']
  9.  
  10. ec2 = Aws::EC2::Resource.new(region: 'us-west-2')
  11. spot_price = ec2.client.describe_spot_price_history(
  12. instance_types: instance_type,
  13. product_descriptions: ['Linux/UNIX'],
  14. start_time: (Time.now - 1).iso8601(3),
  15. end_time: Time.now.iso8601(3)
  16. )
  17.  
  18. h = {}
  19.  
  20. spot_price[:spot_price_history].each do |sp|
  21. puts "#{sp[:instance_type]} #{sp[:availability_zone]} at $#{sp[:spot_price]}"
  22. h.store(sp[:availability_zone], sp[:spot_price].to_f)
  23. end
  24.  
  25. min_spot_price = h.select { |_k, v| v == h.values.min }
  26.  
  27. puts min_spot_price
  28.  
  29. puts "$#{h.values.min} is the lowest price, this is #{(h.values.min.to_f/0.862*100)}%"
  30. puts "hourly savings: $#{(0.862 - h.values.min.to_f)} "
  31. puts "daily savings: $#{(0.862 - h.values.min.to_f) * 24}"
  32. puts "monthly savings: $#{(0.862 - h.values.min.to_f) * 24 * 31}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement