You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::Core::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/core/client.rb

Overview

Base client class for all of the Amazon AWS service clients.

Defined Under Namespace

Classes: NetworkError

Constant Summary

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Creates a new low-level client.

Parameters:

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

Options Hash (options):

  • :config (Core::Configuration) — default: AWS.config

    The base configuration object to use. All other options are merged with this. Defaults to the AWS.config.

  • :access_key_id (String)

    AWS access key id credential.

  • :secret_access_key (String)

    AWS secret access key credential.

  • :session_token (String, nil)

    AWS secret token credential.

  • :region (String) — default: 'us-east-1'

    The default AWS region.

  • :dynamo_db_big_decimals (Boolean) — default: true

    When true, DynamoDB will convert number values returned by DynamoDB::Client from strings to BigDecimal objects. If you set this to false, they will be converted from strings into floats (with a potential loss of precision).

  • :dynamo_db_retry_throughput_errors (Boolean) — default: true

    When true, AWS::DynamoDB::Errors::ProvisionedThroughputExceededException errors will be retried.

  • :http_handler (Object) — default: AWS::Core::Http::NetHttpHandler

    The http handler that sends requests to AWS.

  • :http_idle_timeout (Integer) — default: 60

    The number of seconds a persistent connection is allowed to sit idle before it should no longer be used.

  • :http_open_timeout (Integer) — default: 15

    The number of seconds before the :http_handler should timeout while trying to open a new HTTP session.

  • :http_read_timeout (Integer) — default: 60

    The number of seconds before the :http_handler should timeout while waiting for a HTTP response.

  • :http_wire_trace (Boolean) — default: false

    When true, the http handler will log all wire traces to the :logger. If a :logger is not configured, then wire traces will be sent to standard out.

  • :logger (Logger, nil) — default: nil

    A logger to send log messages to. Here is an example that logs to standard out.

    require 'logger'
    AWS.config(:logger => Logger.new($stdout))
    
  • :log_level (Symbol) — default: :info

    The level log messages are sent to the logger with (e.g. :notice, :info, :warn, :debug, etc).

  • :log_formatter (Object)

    The log formatter is responsible for building log messages from responses. You can quickly change log formats by providing a pre-configured log formatter.

    AWS.config(:log_formatter => AWS::Core::LogFormatter.colored)
    

    Here is a list of pre-configured log formatters:

    • AWS::Core::LogFormatter.default
    • AWS::Core::LogFormatter.short
    • AWS::Core::LogFormatter.debug
    • AWS::Core::LogFormatter.colored

    You can also create an instance of AWS::Core::LogFormatter with a custom log message pattern. See LogFormatter for a complete list of pattern substitutions.

    pattern = "[AWS :operation :duration] :error_message"
    AWS.config(:log_formatter => AWS::Core::LogFormatter.new(pattern))
    

    Lastly you can pass any object that responds to #format accepting and instance of Response and returns a string.

  • :max_retries (Integer) — default: 3

    The maximum number of times service errors (500) and throttling errors should be retried. There is an exponential backoff in between retries, so the more retries the longer it can take to fail.

  • :proxy_uri (String, URI, nil) — default: nil

    The URI of the proxy to send service requests through. You can pass a URI object or a URI string:

    AWS.config(:proxy_uri => 'https://user:password@my.proxy:443/path?query')
    
  • :s3_force_path_style (Boolean) — default: false

    When true, requests will always use path style. This can be useful for testing environments.

  • :s3_multipart_max_parts (Integer) — default: 10000

    The maximum number of parts to split a file into when uploading in parts to S3.

  • :s3_multipart_threshold (Integer) — default: 16777216

    When uploading data to S3, if the number of bytes to send exceeds :s3_multipart_threshold then a multi part session is automatically started and the data is sent up in chunks. The size of each part is specified by :s3_multipart_min_part_size. Defaults to 16777216 (16MB).

  • :s3_multipart_min_part_size (Integer) — default: 5242880

    The absolute minimum size (in bytes) each S3 multipart segment should be. Defaults to 5242880 (5MB).

  • :s3_server_side_encryption (Symbol) — default: nil

    The algorithm to use when encrypting object data on the server side. The only valid value is :aes256, which specifies that the object should be stored using the AES encryption algorithm with 256 bit keys. Defaults to nil, meaning server side encryption is not used unless specified on each individual call to upload an object. This option controls the default behavior for the following methods:

  • :s3_encryption_key (OpenSSL::PKey::RSA, String) — default: nil

    If this is set, AWS::S3::S3Object #read and #write methods will always perform client-side encryption with this key. The key can be overridden at runtime by using the :encryption_key option. A value of nil means that client-side encryption will not be used.

  • :s3_encryption_materials_location (Symbol) — default: :metadata

    When set to :instruction_file, AWS::S3::S3Object will store encryption materials in a separate object, instead of the object metadata.

  • :simple_db_consistent_reads (Boolean) — default: false

    Determines if all SimpleDB read requests should be done consistently. Consistent reads are slower, but reflect all changes to SDB.

  • :credential_provider (CredentialProviders::Provider) — default: AWS::Core::CredentialProviders::DefaultProvider.new

    Returns the credential provider. The default credential provider attempts to check for statically assigned credentials, ENV credentials and credentials in the metadata service of EC2.

  • :ssl_ca_file (String)

    The path to a CA cert bundle in PEM format.

    If :ssl_verify_peer is true (the default) this bundle will be used to validate the server certificate in each HTTPS request. The AWS SDK for Ruby ships with a CA cert bundle, which is the default value for this option.

  • :ssl_ca_path (String) — default: nil

    The path the a CA cert directory.

  • :ssl_verify_peer (Boolean) — default: true

    When true the HTTP handler validate server certificates for HTTPS requests.

    This option should only be disabled for diagnostic purposes; leaving this option set to false exposes your application to man-in-the-middle attacks and can pose a serious security risk.

  • :stub_requests (Boolean) — default: false

    When true requests are not sent to AWS, instead empty responses are generated and returned to each service request.

  • :use_ssl (Boolean) — default: true

    When true, all requests to AWS are sent using HTTPS instead vanilla HTTP.

  • :user_agent_prefix (String) — default: nil

    A string prefix to append to all requests against AWS services. This should be set for clients and applications built ontop of the aws-sdk gem.

  • :verify_response_body_content_length (Boolean) — default: true

    When true all HTTP handlers will perform a check to ensure that response bodies match the content-length specified in the response header, if present. Note that some HTTP handlers will always do this whether or not this value is true.

  • :sqs_verify_checksums (Boolean) — default: true

    When true all SQS operations will check body content against MD5 checksums, raising an exception if there is a mismatch.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/aws/core/client.rb', line 43

def initialize options = {}

  options = options.dup # so we don't modify the options passed in

  @service_ruby_name = self.class.service_ruby_name

  # translate these into service specific configuration options,
  # e.g. :endpoint into :s3_endpoint
  [:endpoint, :region, :port, :signature_version].each do |opt|
    if options[opt]
      options[:#{service_ruby_name}_#{opt}"] = options.delete(opt)
    end
  end

  @config = (options.delete(:config) || AWS.config)
  @config = @config.with(options)

  @region = @config.send(:#{service_ruby_name}_region")

  @credential_provider = @config.credential_provider
  @http_handler = @config.http_handler
  @endpoint = config.send(:#{service_ruby_name}_endpoint")
  @port = config.send(:#{service_ruby_name}_port")

  # deprecated attributes
  @http_read_timeout = @config.http_read_timeout
end

Instance Attribute Details

#configConfiguration (readonly)

Returns This clients configuration.

Returns:



72
73
74
# File 'lib/aws/core/client.rb', line 72

def config
  @config
end

Instance Method Details

#log_warning(warning) ⇒ nil

Logs the warning to the configured logger, otherwise to stderr.

Parameters:

  • warning (String)

Returns:

  • (nil)


174
175
176
177
178
179
180
181
182
# File 'lib/aws/core/client.rb', line 174

def log_warning warning
  message = '[aws-sdk-gem-warning] ' + warning
  if config.logger
    config.logger.warn(message)
  else
    $stderr.puts(message)
  end
  nil
end

#operationsArray<Symbol>

Returns a list of service operations as method names supported by this client.

Returns:

  • (Array<Symbol>)

    Returns a list of service operations as method names supported by this client.



100
101
102
# File 'lib/aws/core/client.rb', line 100

def operations
  self.class.operations
end

#with_http_handler(handler = nil, &blk) ⇒ Core::Client

Returns a copy of the client with a different HTTP handler. You can pass an object like BuiltinHttpHandler or you can use a block; for example:

s3_with_logging = s3.with_http_handler do |request, response| $stderr.puts request.inspect super(request, response) $stderr.puts response.inspect end

The block executes in the context of an HttpHandler instance, and super delegates to the HTTP handler used by this client. This provides an easy way to spy on requests and responses. See HttpHandler, HttpRequest, and HttpResponse for more details on how to implement a fully functional HTTP handler using a different HTTP library than the one that ships with Ruby.

Parameters:

  • handler (nil) (defaults to: nil)

    A new http handler. Leave blank and pass a block to wrap the current handler with the block.

Returns:

  • (Core::Client)

    Returns a new instance of the client class with the modified or wrapped http handler.



125
126
127
128
# File 'lib/aws/core/client.rb', line 125

def with_http_handler(handler = nil, &blk)
  handler ||= Http::Handler.new(@http_handler, &blk)
  with_options(:http_handler => handler)
end

#with_options(options) ⇒ Client

Returns a new client with the passed configuration options merged with the current configuration options.

no_retry_client = client.with_options(:max_retries => 0)

Parameters:

  • options (Hash)

Options Hash (options):

  • :access_key_id (String)

    AWS access key id credential.

  • :secret_access_key (String)

    AWS secret access key credential.

  • :session_token (String, nil)

    AWS secret token credential.

  • :region (String) — default: 'us-east-1'

    The default AWS region.

  • :dynamo_db_big_decimals (Boolean) — default: true

    When true, DynamoDB will convert number values returned by DynamoDB::Client from strings to BigDecimal objects. If you set this to false, they will be converted from strings into floats (with a potential loss of precision).

  • :dynamo_db_retry_throughput_errors (Boolean) — default: true

    When true, AWS::DynamoDB::Errors::ProvisionedThroughputExceededException errors will be retried.

  • :http_handler (Object) — default: AWS::Core::Http::NetHttpHandler

    The http handler that sends requests to AWS.

  • :http_idle_timeout (Integer) — default: 60

    The number of seconds a persistent connection is allowed to sit idle before it should no longer be used.

  • :http_open_timeout (Integer) — default: 15

    The number of seconds before the :http_handler should timeout while trying to open a new HTTP session.

  • :http_read_timeout (Integer) — default: 60

    The number of seconds before the :http_handler should timeout while waiting for a HTTP response.

  • :http_wire_trace (Boolean) — default: false

    When true, the http handler will log all wire traces to the :logger. If a :logger is not configured, then wire traces will be sent to standard out.

  • :logger (Logger, nil) — default: nil

    A logger to send log messages to. Here is an example that logs to standard out.

    require 'logger'
    AWS.config(:logger => Logger.new($stdout))
    
  • :log_level (Symbol) — default: :info

    The level log messages are sent to the logger with (e.g. :notice, :info, :warn, :debug, etc).

  • :log_formatter (Object)

    The log formatter is responsible for building log messages from responses. You can quickly change log formats by providing a pre-configured log formatter.

    AWS.config(:log_formatter => AWS::Core::LogFormatter.colored)
    

    Here is a list of pre-configured log formatters:

    • AWS::Core::LogFormatter.default
    • AWS::Core::LogFormatter.short
    • AWS::Core::LogFormatter.debug
    • AWS::Core::LogFormatter.colored

    You can also create an instance of AWS::Core::LogFormatter with a custom log message pattern. See LogFormatter for a complete list of pattern substitutions.

    pattern = "[AWS :operation :duration] :error_message"
    AWS.config(:log_formatter => AWS::Core::LogFormatter.new(pattern))
    

    Lastly you can pass any object that responds to #format accepting and instance of Response and returns a string.

  • :max_retries (Integer) — default: 3

    The maximum number of times service errors (500) and throttling errors should be retried. There is an exponential backoff in between retries, so the more retries the longer it can take to fail.

  • :proxy_uri (String, URI, nil) — default: nil

    The URI of the proxy to send service requests through. You can pass a URI object or a URI string:

    AWS.config(:proxy_uri => 'https://user:password@my.proxy:443/path?query')
    
  • :s3_force_path_style (Boolean) — default: false

    When true, requests will always use path style. This can be useful for testing environments.

  • :s3_multipart_max_parts (Integer) — default: 10000

    The maximum number of parts to split a file into when uploading in parts to S3.

  • :s3_multipart_threshold (Integer) — default: 16777216

    When uploading data to S3, if the number of bytes to send exceeds :s3_multipart_threshold then a multi part session is automatically started and the data is sent up in chunks. The size of each part is specified by :s3_multipart_min_part_size. Defaults to 16777216 (16MB).

  • :s3_multipart_min_part_size (Integer) — default: 5242880

    The absolute minimum size (in bytes) each S3 multipart segment should be. Defaults to 5242880 (5MB).

  • :s3_server_side_encryption (Symbol) — default: nil

    The algorithm to use when encrypting object data on the server side. The only valid value is :aes256, which specifies that the object should be stored using the AES encryption algorithm with 256 bit keys. Defaults to nil, meaning server side encryption is not used unless specified on each individual call to upload an object. This option controls the default behavior for the following methods:

  • :s3_encryption_key (OpenSSL::PKey::RSA, String) — default: nil

    If this is set, AWS::S3::S3Object #read and #write methods will always perform client-side encryption with this key. The key can be overridden at runtime by using the :encryption_key option. A value of nil means that client-side encryption will not be used.

  • :s3_encryption_materials_location (Symbol) — default: :metadata

    When set to :instruction_file, AWS::S3::S3Object will store encryption materials in a separate object, instead of the object metadata.

  • :simple_db_consistent_reads (Boolean) — default: false

    Determines if all SimpleDB read requests should be done consistently. Consistent reads are slower, but reflect all changes to SDB.

  • :credential_provider (CredentialProviders::Provider) — default: AWS::Core::CredentialProviders::DefaultProvider.new

    Returns the credential provider. The default credential provider attempts to check for statically assigned credentials, ENV credentials and credentials in the metadata service of EC2.

  • :ssl_ca_file (String)

    The path to a CA cert bundle in PEM format.

    If :ssl_verify_peer is true (the default) this bundle will be used to validate the server certificate in each HTTPS request. The AWS SDK for Ruby ships with a CA cert bundle, which is the default value for this option.

  • :ssl_ca_path (String) — default: nil

    The path the a CA cert directory.

  • :ssl_verify_peer (Boolean) — default: true

    When true the HTTP handler validate server certificates for HTTPS requests.

    This option should only be disabled for diagnostic purposes; leaving this option set to false exposes your application to man-in-the-middle attacks and can pose a serious security risk.

  • :stub_requests (Boolean) — default: false

    When true requests are not sent to AWS, instead empty responses are generated and returned to each service request.

  • :use_ssl (Boolean) — default: true

    When true, all requests to AWS are sent using HTTPS instead vanilla HTTP.

  • :user_agent_prefix (String) — default: nil

    A string prefix to append to all requests against AWS services. This should be set for clients and applications built ontop of the aws-sdk gem.

  • :verify_response_body_content_length (Boolean) — default: true

    When true all HTTP handlers will perform a check to ensure that response bodies match the content-length specified in the response header, if present. Note that some HTTP handlers will always do this whether or not this value is true.

  • :sqs_verify_checksums (Boolean) — default: true

    When true all SQS operations will check body content against MD5 checksums, raising an exception if there is a mismatch.

Returns:



138
139
140
# File 'lib/aws/core/client.rb', line 138

def with_options options
  with_config(config.with(options))
end