Class: Elasticity::AwsSession

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AwsSession

Supported values for options:

:region - AWS region (e.g. us-west-1)
:secure - true or false, default true.


15
16
17
18
19
20
21
22
23
24
# File 'lib/elasticity/aws_session.rb', line 15

def initialize(options={})
  # There is a cryptic error if this isn't set
  if options.has_key?(:region) && options[:region] == nil
    raise MissingRegionError, 'A valid :region is required to connect to EMR'
  end
  options[:region] = 'us-east-1' unless options[:region]
  @region = options[:region]

  @host = "elasticmapreduce.#@region.amazonaws.com"
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/elasticity/aws_session.rb', line 9

def host
  @host
end

#regionObject (readonly)

Returns the value of attribute region.



10
11
12
# File 'lib/elasticity/aws_session.rb', line 10

def region
  @region
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
40
41
# File 'lib/elasticity/aws_session.rb', line 37

def ==(other)
  return false unless other.is_a? AwsSession
  return false unless @host == other.host
  true
end

#submit(ruby_service_hash) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/elasticity/aws_session.rb', line 26

def submit(ruby_service_hash)
  aws_request = AwsRequestV4.new(self, ruby_service_hash)
  begin
    RestClient.post(aws_request.url, aws_request.payload, aws_request.headers)
  rescue RestClient::BadRequest => e
    type, message = AwsSession.parse_error_response(e.http_body)
    raise ThrottlingException, message if type == 'ThrottlingException'
    raise ArgumentError, message
  end
end