class AwsPricing::InstanceType

InstanceType is a specific type of instance in a region with a defined price per hour. The price will vary by platform (Linux, Windows).

e.g. m1.large instance in US-East region will cost $0.34/hour for Linux and $0.48/hour for Windows.

Constants

PER_SEC_CAPACITIES
MB/s capacity, Ops/s capacity

EBSoptimized published capacities:

- cf: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html
- MB/s (128KB I/O size), IOPS (16KB IO size)

Attributes

api_name[RW]
compute_units[RW]
disk_in_gb[RW]
disk_type[RW]
memory_in_mb[RW]
name[RW]
platform[RW]
virtual_cores[RW]

Public Class Methods

disk_bytes_per_sec_capacity(api_name) click to toggle source

Returns the bytes/s capacity if defined, `nil` otherwise

    # File lib/amazon-pricing/definitions/instance-type.rb
121 def self.disk_bytes_per_sec_capacity(api_name)
122   if PER_SEC_CAPACITIES[api_name]
123     PER_SEC_CAPACITIES[api_name][0] * 1024 * 1024
124   end
125 end
disk_ops_per_sec_capacity(api_name) click to toggle source

Returns the ops/s capacity if defined, `nil` otherwise

    # File lib/amazon-pricing/definitions/instance-type.rb
128 def self.disk_ops_per_sec_capacity(api_name)
129   if PER_SEC_CAPACITIES[api_name]
130     PER_SEC_CAPACITIES[api_name][1]
131   end
132 end
get_descriptive_cache_name(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
138 def self.get_descriptive_cache_name(api_name)
139   @@Cache_Name_Lookup[api_name]
140 end
get_descriptive_name(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
134 def self.get_descriptive_name(api_name)
135   @@Name_Lookup[api_name]
136 end
new(region, api_name, name) click to toggle source
   # File lib/amazon-pricing/definitions/instance-type.rb
25 def initialize(region, api_name, name)
26   @category_types = {}
27 
28   @region = region
29   @name = name
30   @api_name = api_name
31 
32   @disk_in_gb = InstanceType.get_disk(api_name)
33   @platform = InstanceType.get_platform(api_name)
34   @disk_type = InstanceType.get_disk_type(api_name)
35   @memory_in_mb = InstanceType.get_memory(api_name)
36   @compute_units = InstanceType.get_compute_units(api_name)
37   @virtual_cores = InstanceType.get_virtual_cores(api_name)
38 end
populate_lookups() click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
 96 def self.populate_lookups
 97   # We use Linux on-demand to populate the lookup tables with the basic lookup information
 98   ["http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js", "http://a0.awsstatic.com/pricing/1/ec2/previous-generation/linux-od.min.js"].each do |url|
 99     res = AwsPricing::PriceList.fetch_url(url)
100 
101     res['config']['regions'].each do |reg|
102       reg['instanceTypes'].each do |type|
103         items = type['sizes']
104         items = [type] if items.nil?
105         items.each do |size|
106           begin
107             api_name = size["size"]
108             @@Memory_Lookup[api_name] = size["memoryGiB"].to_f * 1000
109             @@Compute_Units_Lookup[api_name] = size["ECU"].to_f
110             @@Virtual_Cores_Lookup[api_name] = size["vCPU"].to_i
111           rescue UnknownTypeError
112             $stderr.puts "[populate_lookups] WARNING: encountered #{$!.message}"
113           end
114         end
115       end
116     end
117   end
118 end
service_type(category) click to toggle source
   # File lib/amazon-pricing/definitions/instance-type.rb
86 def self.service_type(category)
87   case category
88     when 'os'; 'ec2'
89     when 'db'; 'rds'
90     when 'cache'; 'elasticache'
91     else
92       ''
93   end
94 end

Protected Class Methods

get_compute_units(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
160 def self.get_compute_units(api_name)
161   @@Compute_Units_Lookup[api_name]
162 end
get_disk(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
144 def self.get_disk(api_name)
145   @@Disk_Lookup[api_name]
146 end
get_disk_type(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
152 def self.get_disk_type(api_name)
153   @@Disk_Type_Lookup[api_name]
154 end
get_memory(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
156 def self.get_memory(api_name)
157   @@Memory_Lookup[api_name]
158 end
get_platform(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
148 def self.get_platform(api_name)
149   @@Platform_Lookup[api_name]
150 end
get_values(json, category_type, override_price = false) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
173 def self.get_values(json, category_type, override_price = false)
174   values = {}
175   unless json['valueColumns'].nil?
176     json['valueColumns'].each do |val|
177       values[val['name']] = val['prices']['USD']
178       # AWS has data entry errors where you go to a windows pricing URL (e.g. http://a0.awsstatic.com/pricing/1/ec2/mswin-od.min.js)
179       # but get a value for on-demand other than mswin
180       values[category_type.to_s] = val['prices']['USD'] if override_price
181     end
182   else
183     values[category_type.to_s] = json['prices']['USD']
184   end
185   values
186 end
get_virtual_cores(api_name) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
164 def self.get_virtual_cores(api_name)
165   @@Virtual_Cores_Lookup[api_name]
166 end

Public Instance Methods

category_types() click to toggle source
   # File lib/amazon-pricing/definitions/instance-type.rb
49 def category_types
50   @category_types.values
51 end
disk_in_mb() click to toggle source

Keep this in for backwards compatibility within current major version of gem

   # File lib/amazon-pricing/definitions/instance-type.rb
41 def disk_in_mb
42   @disk_in_gb.nil? ? 0 : @disk_in_gb * 1000
43 end
get_breakeven_month(category_types, type_of_instance, term, is_multi_az = false, isByol = false) click to toggle source

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil

   # File lib/amazon-pricing/definitions/instance-type.rb
81 def get_breakeven_month(category_types, type_of_instance, term, is_multi_az = false, isByol = false)
82   cat = get_category_type(category_types, is_multi_az, isByol)
83   cat.get_breakeven_month(type_of_instance, term) unless cat.nil?
84 end
get_category_type(name, multi_az = false, byol = false) click to toggle source
   # File lib/amazon-pricing/definitions/instance-type.rb
53 def get_category_type(name, multi_az = false, byol = false)
54   if multi_az == true and byol == true
55     db = @category_types["#{name}_byol_multiaz"]
56   elsif multi_az == true and byol == false
57     db = @category_types["#{name}_multiaz"]
58   elsif multi_az == false and byol == true
59     db = @category_types["#{name}_byol"]
60   else
61     db = @category_types[name]
62   end
63 end
memory_in_gb() click to toggle source
   # File lib/amazon-pricing/definitions/instance-type.rb
45 def memory_in_gb
46   @memory_in_mb / 1000
47 end
prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) click to toggle source

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil

   # File lib/amazon-pricing/definitions/instance-type.rb
74 def prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false)
75   cat = get_category_type(category_type, is_multi_az, isByol)
76   cat.prepay(type_of_instance, term) unless cat.nil?
77 end
price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) click to toggle source

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil

   # File lib/amazon-pricing/definitions/instance-type.rb
67 def price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false)
68   cat = get_category_type(category_type, is_multi_az, isByol)
69   cat.price_per_hour(type_of_instance, term) unless cat.nil?
70 end

Protected Instance Methods

coerce_price(price) click to toggle source
    # File lib/amazon-pricing/definitions/instance-type.rb
168 def coerce_price(price)
169   return nil if price.nil? || price.upcase == "N/A"
170   price.gsub(",","").gsub("$", "").to_f
171 end