Module: Qurd::Mixins::AwsClients

Included in:
Action, Action, Listener, Qurd::Message, Processor
Defined in:
lib/qurd/mixins/aws_clients.rb

Overview

Generic method for instantiating Aws clients

Instance Method Summary collapse

Instance Method Details

#aws_client(client) ⇒ Object

Memoize Aws clients, the caller must respond to region and aws_credentials

Examples:

SQS

executor.aws_client(:SQS).list_queues

EC2

executor.aws_client("EC2").describe_instances

Parameters:

  • client (String|Symbol)

    the name of the client to instantiate

Returns:

  • (Object)

    an Aws client

Raises:

  • (NameError)

    if the client is not a valid Aws client class



14
15
16
17
18
19
20
# File 'lib/qurd/mixins/aws_clients.rb', line 14

def aws_client(client)
  @qurd_aws_clients ||= {}
  klass = Object.const_get("Aws::#{client}::Client")
  @qurd_aws_clients[client.to_sym] ||= klass.new(
    region: region,
    credentials: aws_credentials)
end

#aws_retryable(tries = 2) ⇒ Object

Wrap a block in a begin rescue, which retries, if Aws::Errors::ServiceError is raised. The method will retry the block immediately, up to n tries.

Parameters:

  • tries (Fixnum) (defaults to: 2)

Raises:

  • (Aws::Errors::ServiceError)

    Any number of Aws error classes



27
28
29
30
31
32
33
34
# File 'lib/qurd/mixins/aws_clients.rb', line 27

def aws_retryable(tries = 2)
  tries = [1, tries.to_i].max
  begin
    yield
  rescue Aws::Errors::ServiceError => e
    (tries -= 1).zero? ? raise(e) : retry
  end
end