class MultiEc2Kiq::Ec2

Public Class Methods

new(id, region) click to toggle source
# File lib/threads/ec2.rb, line 7
def initialize(id, region)
  @id = id
  @region = region
end

Public Instance Methods

start() click to toggle source
# File lib/threads/ec2.rb, line 12
def start
  start_instance
  puts_started_message
  true
end
start_wait_until_stop() click to toggle source
# File lib/threads/ec2.rb, line 18
def start_wait_until_stop
  start
  dynamodb.started(@id)

  if dynamodb.wait_until_to_stop(@id)
    stop_instance
    dynamodb.stopped(@id)
  end
  
  true
end

Private Instance Methods

dynamodb() click to toggle source
# File lib/threads/ec2.rb, line 53
def dynamodb
  @dynamodb ||= Dynamodb.new
end
ec2() click to toggle source
# File lib/threads/ec2.rb, line 46
def ec2
  @ec2 ||= Aws::EC2::Client.new(
    region: @region,
    profile: Settings.aws.profile
  )
end
puts_started_message() click to toggle source
# File lib/threads/ec2.rb, line 32
def puts_started_message
  puts Time.now.to_s + " EC2 started. id = " + @id + ", region = " + @region + "."
end
start_instance() click to toggle source
# File lib/threads/ec2.rb, line 41
def start_instance
  ec2.start_instances(instance_ids: [@id])
  ec2.wait_until(:instance_running,  instance_ids:[@id])
end
stop_instance() click to toggle source
# File lib/threads/ec2.rb, line 36
def stop_instance
  ec2.stop_instances(instance_ids: [@id])
  ec2.wait_until(:instance_stopped,  instance_ids:[@id])
end