Module: Infopark::AwsUtils

Defined in:
lib/infopark/aws_utils.rb,
lib/infopark/aws_utils/env.rb,
lib/infopark/aws_utils/version.rb

Defined Under Namespace

Classes: Env

Constant Summary collapse

AWS_AMI_OWNER =
"137112412989"
DEV_ACCOUNT_ID =
PROD_ACCOUNT_ID =
VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.gather_all(client:, method:, response_key:, **options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/infopark/aws_utils.rb', line 9

def gather_all(client:, method:, response_key:, **options)
  unless block_given?
    @gather_cache ||= {}
    cache_key = [client, method, options]
    return @gather_cache[cache_key] if @gather_cache[cache_key]
  end

  result = []
  loop do
    response = retry_on_throttle { client.send(method, **options) }
    if response.members.include?(:failures) && !response.failures.empty?
      raise "Failed gathering all #{method}: #{response.failures}"
    end
    if block_given?
      response[response_key].each {|entity| retry_on_throttle { yield entity } }
    else
      result += response[response_key]
    end
    unless options[:next_token] = response.members.include?(:next_token) && response.next_token
      break
    end
  end
  @gather_cache[cache_key] = result unless block_given?
end

.wait_for(progress, client, waiter, delay: 2, max_attempts: 60, **waiter_params) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/infopark/aws_utils.rb', line 34

def wait_for(progress, client, waiter, delay: 2, max_attempts: 60, **waiter_params)
  client.wait_until(waiter, waiter_params) do |w|
    w.delay = delay
    w.max_attempts = max_attempts
    w.before_wait { progress.increment }
  end
end