Class: Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_recon/lib/mapper.rb

Overview

Generic wrapper for service clients.

Paging


The AWS Ruby SDK has a built-in enumerator in the client response object that automatically handles paging large requests. Confirm the AWS SDK client call returns a Aws::PageableResponse to take advantage of automatic paging.

Retries


The AWS Ruby SDK performs retries automatically. We change the retry_limit to 9 (10 total requests) and the retry_backoff to add 5 seconds delay on each retry for a total max of 55 seconds.

Constant Summary collapse

SINGLE_REGION_SERVICES =

Services that use us-east-1 endpoint only:

Organizations
Route53Domains
Shield
S3 (unless the bucket was created in another region)
%w[route53domains s3 shield support organizations].freeze

Instance Method Summary collapse

Constructor Details

#initialize(account, service, region, options) ⇒ Mapper

Returns a new instance of Mapper.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aws_recon/lib/mapper.rb', line 27

def initialize(, service, region, options)
  @account = 
  @service = service
  @region = region
  @options = options
  @thread = Parallel.worker_number || 0

  # build the client interface
  module_name = "Aws::#{service}::Client"

  # incremental delay on retries (seconds)
  retry_delay = 5

  # default is 3 retries, with 15 second sleep in between
  # reset to 9 retries, with incremental backoff
  client_options = {
    retry_mode: 'legacy', # legacy, standard, or adaptive
    retry_limit: 9, # only legacy
    retry_backoff: ->(context) { sleep(retry_delay * context.retries + 1) }, # only legacy
    http_read_timeout: 10
  }

  # regional service
  client_options.merge!({ region: region }) unless region == 'global'

  # single region services
  client_options.merge!({ region: 'us-east-1' }) if SINGLE_REGION_SERVICES.include?(service.downcase) # rubocop:disable Layout/LineLength

  # debug with wire trace
  client_options.merge!({ http_wire_trace: true }) if @options.debug

  @client = Object.const_get(module_name).new(client_options)
end