Class: Cluster::Discovery::EC2::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/cluster/discovery/ec2/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_region:) ⇒ Aws::EC2::Client

Initialize the EC2 Client object

Parameters:

  • aws_region: (String)

    The aws region



13
14
15
# File 'lib/cluster/discovery/ec2/tag.rb', line 13

def initialize(aws_region:)
  @ec2_client ||= Aws::EC2::Client.new(region: aws_region)
end

Instance Attribute Details

#ec2_clientObject (readonly)

The EC2 Client Object



7
8
9
# File 'lib/cluster/discovery/ec2/tag.rb', line 7

def ec2_client
  @ec2_client
end

Instance Method Details

#discover(aws_tags: []) ⇒ Array<Aws::EC2::Types::Instance>

Discover EC2 Instances by Tag

Examples:

For example, aws_tags might look something like this:

[
  { key: "tag:Service", values: ["MyService"] },
  { key: "tag:Purpose", values: ["MyPurpose"] }
]

Parameters:

  • aws_tags (Array<Hash>) (defaults to: [])

    AWS Tags to limit discovery

Options Hash (aws_tags:):

  • :key (String)

    The name of the tag

  • :values (Array<String>)

    The value(s) of the tag

Returns:

  • (Array<Aws::EC2::Types::Instance>)

    Array of EC2 Instance objects



29
30
31
32
# File 'lib/cluster/discovery/ec2/tag.rb', line 29

def discover(aws_tags: [])
  fail EmptyTagsError if aws_tags.empty?
  discover_instances_by_tags(build_tags(aws_tags))
end