Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # request spot instance requests
- require 'aws-sdk'
- require 'pry'
- instance_type = ['m4.4xlarge']
- ec2 = Aws::EC2::Resource.new(region: 'us-west-2')
- spot_price = ec2.client.describe_spot_price_history(
- instance_types: instance_type,
- product_descriptions: ['Linux/UNIX'],
- start_time: (Time.now - 1).iso8601(3),
- end_time: Time.now.iso8601(3)
- )
- h = {}
- spot_price[:spot_price_history].each do |sp|
- puts "#{sp[:instance_type]} #{sp[:availability_zone]} at $#{sp[:spot_price]}"
- h.store(sp[:availability_zone], sp[:spot_price].to_f)
- end
- min_spot_price = h.select { |_k, v| v == h.values.min }
- puts min_spot_price
- puts "$#{h.values.min} is the lowest price, this is #{(h.values.min.to_f/0.862*100)}%"
- puts "hourly savings: $#{(0.862 - h.values.min.to_f)} "
- puts "daily savings: $#{(0.862 - h.values.min.to_f) * 24}"
- puts "monthly savings: $#{(0.862 - h.values.min.to_f) * 24 * 31}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement