module Meroku::Aws

Mostly wrappers around aws library functions

Public Class Methods

running_filter(tag) click to toggle source
# File lib/meroku/aws.rb, line 84
def self.running_filter(tag)
  [
    { name: 'tag:Name', values: [tag] },
    { name: 'instance-state-name', values: %w[running pending] }
  ]
end
terminate_all(tag: nil) click to toggle source
# File lib/meroku/aws.rb, line 53
def self.terminate_all(tag: nil)
  Meroku::Shared.ec2_client.describe_instances(
    filters: running_filter(tag)
  ).reservations.map do |r|
    id = r.instances.first.instance_id
    puts "Will terminate #{id}"
    Meroku::Shared.ec2_client.terminate_instances(instance_ids: [id])
  end
end

Public Instance Methods

allocation_id() click to toggle source

Our elastic ip allocation

# File lib/meroku/aws.rb, line 64
def allocation_id
  'eipalloc-139f7823'
end
associate_address() click to toggle source
# File lib/meroku/aws.rb, line 32
def associate_address
  sleep 15
  Meroku::Shared.ec2_client.associate_address(
    allocation_id: allocation_id, instance_id: instance_id
  )
  # TODO: stub this in tests
  print '*'
  sleep 25
  print '*'
  TCPSocket.new '34.239.241.218', 22
  # Socket.tcp("www.meroku.com", 22, connect_timeout: 60) {}
  puts '*'
end
bucket() click to toggle source

Private S3 Bucket The only security here is not no one knows the bucket name, which is a uuid

# File lib/meroku/aws.rb, line 49
def bucket
  "http://s3.amazonaws.com/#{Meroku::Shared.secrets.meroku_secret}/"
end
default_instance_params() click to toggle source
# File lib/meroku/aws.rb, line 8
def default_instance_params
  {
    image_id: 'ami-841f46ff',
    min_count: 1,
    max_count: 1,
    key_name: 'meroku.id_rsa',
    instance_type: 't2.micro',
    tag_specifications: [tag]
  }
end
ip_address() click to toggle source
# File lib/meroku/aws.rb, line 68
def ip_address
  '34.239.241.218'
end
make_instance() click to toggle source
# File lib/meroku/aws.rb, line 19
def make_instance
  @instance_id =
    Meroku::Shared \
    .ec2_client  \
    .run_instances(default_instance_params) \
    .instances.fetch(0).instance_id
  puts 'waiting'
  Meroku::Shared.ec2_client.wait_until(
    :instance_running,
    instance_ids: [@instance_id]
  )
end
tag() click to toggle source
# File lib/meroku/aws.rb, line 72
def tag
  {
    resource_type: 'instance',
    tags: [
      {
        key: 'Name',
        value: 'node'
      }
    ]
  }
end