Class: AWS::Core::Client
- Inherits:
-
Object
- Object
- AWS::Core::Client
- 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.
Direct Known Subclasses
AutoScaling::Client, AWS::CloudFormation::Client, DynamoDB::Client, EC2::Client, ELB::Client, IAM::Client, S3::Client, SNS::Client, SQS::Client, STS::Client, SimpleDB::Client, SimpleEmailService::Client, SimpleWorkflow::Client
Defined Under Namespace
Instance Attribute Summary collapse
-
#config ⇒ Configuration
readonly
This clients configuration.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new low-level client.
- #operations ⇒ Object
-
#with_config(config) ⇒ Core::Client
Returns a new client object with the given configuration.
-
#with_http_handler(handler = nil, &blk) ⇒ Core::Client
Returns a copy of the client with a different HTTP handler.
- #with_options(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new low-level client.
Required Options
To create a client you must provide access to AWS credentials. There are two options:
-
:signer
– An object that responds toaccess_key_id
(to return the AWS Access Key ID) and tosign(string_to_sign)
(to return a signature for a given string). An example implementation is AWS::Core::DefaultSigner. This option is useful if you want to more tightly control access to your secret access key (for example by moving the signature computation into a different process). -
:access_key_id
and:secret_access_key
– You can use these options to provide the AWS Access Key ID and AWS Secret Access Key directly to the client.
Optional
-
:http_handler
– Any object that implements ahandle(request, response)
method; an example is BuiltinHttpHandler. This method is used to perform the HTTP requests that this client constructs.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/aws/core/client.rb', line 56 def initialize = {} = .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 [opt] [:"#{service_ruby_name}_#{opt}"] = .delete(opt) end end @config = .delete(:config) @config ||= AWS.config @config = @config.with() @signer = @config.signer @http_handler = @config.http_handler @endpoint = config.send(:"#{service_ruby_name}_endpoint") @port = config.send(:"#{service_ruby_name}_port") end |
Instance Attribute Details
#config ⇒ Configuration (readonly)
Returns This clients configuration.
82 83 84 |
# File 'lib/aws/core/client.rb', line 82 def config @config end |
Instance Method Details
#operations ⇒ Object
105 106 107 |
# File 'lib/aws/core/client.rb', line 105 def operations self.class.operations end |
#with_config(config) ⇒ Core::Client
Returns a new client object with the given configuration.
143 144 145 |
# File 'lib/aws/core/client.rb', line 143 def with_config config self.class.new(:config => config) 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
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.
129 130 131 132 |
# File 'lib/aws/core/client.rb', line 129 def with_http_handler(handler = nil, &blk) handler ||= Http::Handler.new(@http_handler, &blk) (:http_handler => handler) end |
#with_options(options) ⇒ Object
136 137 138 |
# File 'lib/aws/core/client.rb', line 136 def with_config(config.with()) end |