Class: EC2::Host::ClientUtil
- Inherits:
-
Object
- Object
- EC2::Host::ClientUtil
- Defined in:
- lib/ec2/host/client_util.rb
Class Method Summary collapse
Class Method Details
.get_instance_id ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ec2/host/client_util.rb', line 15 def self.get_instance_id return @instance_id if @instance_id begin http_conn = Net::HTTP.new('169.254.169.254') http_conn.open_timeout = 5 @instance_id = http_conn.start {|http| http.get('/latest/meta-data/instance-id').body } rescue Net::OpenTimeout raise "HTTP connection to 169.254.169.254 is timeout. Probably, not an EC2 instance?" end end |
.get_instances ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ec2/host/client_util.rb', line 7 def self.get_instances # I do not use describe_instances(filter:) because it does not support array tag .. return @instances if @instances Aws.config.update(region: Config.aws_region, credentials: Config.aws_credentials) ec2 = Aws::EC2::Client.new @instances = ec2.describe_instances.reservations.map(&:instances).flatten end |