Unfortunately, it seems that there is no direct aws-sdk
module that can be used to access ec2 and ebs costs across all regions. However, it seems that the AWS pricing API will be the closest solution providing costs for both resources across all aws regions.
More details on this api can be found in this post: get ec2 pricing programmatically?
The api produces jsonp files. To make this easily accessible in ruby I would then recommend taking a look at this post that uses examples direcly from the pricing API: Ruby : How to parse a jsonp and save json data to database
Fair warning, you will need to parse this heavily to be able to access any information. For example, this solution will provide a hash containing the pricing data for a t2.medium
instance in us-west-2
#!/usr/bin/env ruby
require 'net/http'
require 'json'
ec2_linux_price = JSON.parse(
Net::HTTP.get(
URI.parse('http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js')
).split('callback(')[1].sub(');', '').gsub(/(\w+):/, '"\1":')
)
region_prices = ec2_linux_price["config"]["regions"].select{|region|
region["region"]=="us-west-2"
}[0]["instanceTypes"].map{|types|
types["sizes"]
}
cost_hash={}
region_prices.each do |size_range|
cost = size_range.select{|size|
size["size"]==instance[:instance_type]
}[0]
unless cost.nil?
cost_hash["t2.medium"] = cost["valueColumns"][0]["prices"]["USD"]
end
end
p cost_hash