Class: AWS::Core::Client

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

Overview

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

Defined Under Namespace

Modules: QueryJSON, QueryXML

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.

  • :auto_scaling_endpoint (String) — default: 'autoscaling.us-east-1.amazonaws.com'

    The service endpoint for Auto Scaling.

  • :cloud_formation_endpoint (String) — default: 'cloudformation.us-east-1.amazonaws.com'

    The service endpoint for AWS CloudFormation.

  • :dynamo_db_endpoint (String) — default: 'dynamodb.amazonaws.com'

    The service endpoint for Amazon DynamoDB.

  • :dynamo_db_retry_throughput_errors (String) — default: true

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

  • :ec2_endpoint (String) — default: 'ec2.amazonaws.com'

    The service endpoint for Amazon EC2.

  • :elb_endpoint (String) — default: 'elasticloadbalancing.us-east-1.amazonaws.com'

    The service endpoint for Elastic Load Balancing.

  • :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 sesssion.

  • :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.

  • :iam_endpoint (String) — default: 'iam.amazonaws.com'

    The service endpoint for AWS Idenity Access Management (IAM).

  • :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 substituions.

    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) should be retried. There is an exponential backoff in between service request 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:[email protected]:443/path?query')
    
  • :s3_endpoint (String) — default: 's3.amazonaws.com'

    The service endpoint for Amazon S3.

  • :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: 1000

    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 exceedes :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:

  • :simple_db_endpoint (String) — default: 'sdb.amazonaws.com'

    The service endpoint for Amazon SimpleDB.

  • :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.

  • :simple_email_service_endpoint (String) — default: 'email.us-east-1.amazonaws.com'

    The service endpoint for Amazon Simple Email Service.

  • :simple_workflow_service (String) — default: 'swf.us-east-1.amazonaws.com'

    The service endpoint for Amazon Simple Workflow Service.

  • :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 reponses are generated and returned to each service request.

  • :sns_endpoint (String) — default: 'sns.us-east-1.amazonaws.com'

    The service endpoint for Amazon SNS.

  • :sqs_endpoint (String) — default: 'sqs.us-east-1.amazonaws.com'

    The service endpoint for Amazon SQS.

  • :sts_endpoint (String) — default: 'sts.amazonaws.com'

    The service endpoint for AWS Security Token Service.

  • :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 requets against AWS services. This should be set for clients and applications built ontop of the aws-sdk gem.



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/core/client.rb', line 36

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].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)

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

end

Instance Attribute Details

#configConfiguration (readonly)

Returns This clients configuration.

Returns:



62
63
64
# File 'lib/aws/core/client.rb', line 62

def config
  @config
end

#http_read_timeoutInteger (readonly)

Returns The number of secords before requests made by this client should timeout if they have not received a response.

Returns:

  • (Integer)

    The number of secords before requests made by this client should timeout if they have not received a response.



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

def http_read_timeout
  @http_read_timeout
end

Instance Method Details

#operationsObject



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

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.



113
114
115
116
# File 'lib/aws/core/client.rb', line 113

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.

  • :auto_scaling_endpoint (String) — default: 'autoscaling.us-east-1.amazonaws.com'

    The service endpoint for Auto Scaling.

  • :cloud_formation_endpoint (String) — default: 'cloudformation.us-east-1.amazonaws.com'

    The service endpoint for AWS CloudFormation.

  • :dynamo_db_endpoint (String) — default: 'dynamodb.amazonaws.com'

    The service endpoint for Amazon DynamoDB.

  • :dynamo_db_retry_throughput_errors (String) — default: true

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

  • :ec2_endpoint (String) — default: 'ec2.amazonaws.com'

    The service endpoint for Amazon EC2.

  • :elb_endpoint (String) — default: 'elasticloadbalancing.us-east-1.amazonaws.com'

    The service endpoint for Elastic Load Balancing.

  • :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 sesssion.

  • :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.

  • :iam_endpoint (String) — default: 'iam.amazonaws.com'

    The service endpoint for AWS Idenity Access Management (IAM).

  • :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 substituions.

    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) should be retried. There is an exponential backoff in between service request 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:[email protected]:443/path?query')
    
  • :s3_endpoint (String) — default: 's3.amazonaws.com'

    The service endpoint for Amazon S3.

  • :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: 1000

    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 exceedes :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:

  • :simple_db_endpoint (String) — default: 'sdb.amazonaws.com'

    The service endpoint for Amazon SimpleDB.

  • :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.

  • :simple_email_service_endpoint (String) — default: 'email.us-east-1.amazonaws.com'

    The service endpoint for Amazon Simple Email Service.

  • :simple_workflow_service (String) — default: 'swf.us-east-1.amazonaws.com'

    The service endpoint for Amazon Simple Workflow Service.

  • :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 reponses are generated and returned to each service request.

  • :sns_endpoint (String) — default: 'sns.us-east-1.amazonaws.com'

    The service endpoint for Amazon SNS.

  • :sqs_endpoint (String) — default: 'sqs.us-east-1.amazonaws.com'

    The service endpoint for Amazon SQS.

  • :sts_endpoint (String) — default: 'sts.amazonaws.com'

    The service endpoint for AWS Security Token Service.

  • :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 requets against AWS services. This should be set for clients and applications built ontop of the aws-sdk gem.

Returns:



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

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