Class: AwsEc2DnsName

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_ec2_dns_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region: nil, access_key_id: nil, secret_access_key: nil) ⇒ AwsEc2DnsName

Returns a new instance of AwsEc2DnsName.

Parameters:

  • region (String) (defaults to: nil)
  • access_key_id (String) (defaults to: nil)
  • secret_access_key (String) (defaults to: nil)


10
11
12
13
14
# File 'lib/aws_ec2_dns_name.rb', line 10

def initialize(region: nil, access_key_id: nil, secret_access_key: nil)
  self.client = Aws::EC2::Client.new(region: region,
                                     access_key_id: access_key_id,
                                     secret_access_key: secret_access_key)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/aws_ec2_dns_name.rb', line 5

def client
  @client
end

Instance Method Details

#listArray<Hash>

Returns:

  • (Array<Hash>)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aws_ec2_dns_name.rb', line 17

def list
  client.describe_instances.first.reservations.map do |reservation|
    instance = reservation.instances.first
    name_tag = instance.tags.find { |tag| tag.key == "Name" }.value
    dns_name = dns_name(instance)
    next if dns_name.nil?

    {
      name_tag: name_tag,
      dns_name: dns_name,
    }
  end.sort_by { |h| h[:name_tag] }
end