Class: AWS::EC2::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/AWS/EC2/instances.rb

Overview

A set of methods for querying amazon's ec2 meta-data service. Note : This can ONLY be run on an actual running EC2 instance.

Example Class Method Usage : instance_id = AWS::EC2::Instance.local_instance_id

Constant Summary

EC2_META_URL_BASE =
'http://169.254.169.254/latest/meta-data/'

Class Method Summary (collapse)

Class Method Details

+ (Object) local_instance_id

Returns the current instance-id when called from a host within EC2.



277
278
279
# File 'lib/AWS/EC2/instances.rb', line 277

def self.local_instance_id
  Net::HTTP.get URI.parse(EC2_META_URL_BASE + 'instance-id')
end

+ (Object) local_instance_meta_data

Returns a hash of all available instance meta data.



284
285
286
287
288
289
290
291
292
# File 'lib/AWS/EC2/instances.rb', line 284

def self.
   = {}

  Net::HTTP.get(URI.parse(EC2_META_URL_BASE)).split("\n").each do |meta_type|
    .merge!({meta_type => Net::HTTP.get(URI.parse(EC2_META_URL_BASE + meta_type)) })
  end

  return 
end