module AwsWatcher::EC2

Public Class Methods

client(config) click to toggle source
# File lib/aws-watcher.rb, line 22
def self.client(config)
  Aws::EC2::Client.new(config[:aws])
end
instance_alive?(id, config) click to toggle source
# File lib/aws-watcher.rb, line 26
def self.instance_alive?(id, config)
  AwsWatcher::EC2.client(config).describe_instance_attribute(
    attribute: 'instanceType',
    instance_id: id.to_s
  )
  true
rescue Aws::EC2::Errors::InvalidInstanceIDNotFound => e
  p "instance: #{id} was not found."
  if ENV['LOG_LEVEL'] == 'DEBUG'
    p e
  end
  false
end
tag_matches?(id, tag, values, config) click to toggle source
# File lib/aws-watcher.rb, line 40
def self.tag_matches?(id, tag, values, config)
  instances = AwsWatcher::EC2.client(config).describe_instances(
    instance_ids: [id],
    filters: [
      {
        name: "tag:#{tag}",
        values: values.to_a
      }
    ]
  )
  if instances.reservations.empty?
    false
  else
    true
  end
end