Class: Aws::Client

Inherits:
Seahorse::Client::Base show all
Defined in:
lib/aws-sdk-core/client.rb

Overview

Base class for all Aws service clients.

Class Attribute Summary collapse

Attributes inherited from Seahorse::Client::Base

#config, #handlers

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Seahorse::Client::Base

add_plugin, api, #build_request, clear_plugins, #initialize, #inspect, #method_missing, new, #operation, #operation_names, plugins, remove_plugin, #respond_to?, set_api, set_plugins

Methods included from Seahorse::Client::HandlerBuilder

#handle, #handle_request, #handle_response, #handler_for, #new_handler

Constructor Details

This class inherits a constructor from Seahorse::Client::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Seahorse::Client::Base

Class Attribute Details

.identifierSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)


88
89
90
# File 'lib/aws-sdk-core/client.rb', line 88

def identifier
  @identifier
end

.paginatorsPaging::Provider

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



92
93
94
# File 'lib/aws-sdk-core/client.rb', line 92

def paginators
  @paginators
end

.waitersWaiters::Provider

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



96
97
98
# File 'lib/aws-sdk-core/client.rb', line 96

def waiters
  @waiters
end

Class Method Details

.define(svc_name, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
104
105
# File 'lib/aws-sdk-core/client.rb', line 99

def define(svc_name, options)
  client_class = Class.new(self)
  client_class.identifier = svc_name.downcase.to_sym
  client_class.set_api(load_api(options[:api]))
  Api::ServiceCustomizations.apply(client_class)
  client_class
end

Instance Method Details

#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Seahorse::Client::Response

Waits until a particular condition is satisfied. This works by polling a client request and checking for particular response data or errors. Waiters each have a default duration max attempts which are configurable. Additionally, you can register callbacks and stop waiters by throwing ‘:success` or `:failure`.

Examples:

Basic usage

client.wait_until(:waiter_name)

Configuring interval and maximum attempts

client.wait_until(:waiter_name) do |w|
  w.interval = 10    # number of seconds to sleep between attempts
  w.max_attempts = 6 # maximum number of polling attempts
end

Rescuing a failed wait

begin
  client.wait_until(:waiter_name)
rescue Aws::Waiters::Errors::WaiterFailed
  # gave up waiting
end

Waiting with progress callbacks

client.wait_until(:waiter_name) do |w|

  # yields just before polling for change
  w.before_attempt do |attempt|
    # attempts - number of previous attempts made
  end

  # yields before sleeping
  w.before_wait do |attempt, prev_response|
    # attempts - number of previous attempts made
    # prev_response - the last client response received
  end
end

Throw :success or :failure to terminate early

# wait for an hour, not for a number of requests
client.wait_until(:waiter_name) do |waiter|
  one_hour = Time.now + 3600
  waiter.max_attempts = nil
  waiter.before_attempt do |attempt|
    throw(:failure, 'waited to long') if Time.now > one_hour
  end
end

Parameters:

  • waiter_name (Symbol)

    The name of the waiter. See #waiter_names for a full list of supported waiters.

  • params (Hash) (defaults to: {})

    Additional request parameters. See the #waiter_names for a list of supported waiters and what request they call. The called request determines the list of accepted parameters.

Yield Parameters:

Returns:

  • (Seahorse::Client::Response)

    Returns the client response from the successful polling request. If ‘:success` is thrown from a callback, then the 2nd argument to `#throw` is returned.

Raises:

  • (Waiters::Errors::NoSuchWaiter)

    Raised when the named waiter is not defined.

  • (Waiters::Errors::WaiterFailed)

    Raised when one of the following conditions is met:

    • A failure condition is detected

    • The maximum number of attempts has been made without success

    • ‘:failure` is thrown from a callback



72
73
74
75
76
# File 'lib/aws-sdk-core/client.rb', line 72

def wait_until(waiter_name, params = {}, &block)
  waiter = self.class.waiters.waiter(waiter_name)
  yield(waiter) if block_given?
  waiter.wait(self, params)
end

#waiter_namesArray<Symbol>

Returns the list of supported waiters.

Returns:

  • (Array<Symbol>)


80
81
82
# File 'lib/aws-sdk-core/client.rb', line 80

def waiter_names
  self.class.waiters.waiter_names
end