Class: DynamoDB::Connection
- Inherits:
-
Object
- Object
- DynamoDB::Connection
- Defined in:
- lib/dynamodb/connection.rb
Overview
Establishes a connection to Amazon DynamoDB using credentials.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Connection
constructor
Create a connection uri: # default ‘dynamodb.us-east-1.amazonaws.com/’ timeout: # default 5 seconds api_version: # default.
-
#post(operation, body = {}) ⇒ Object
Create and send a request to DynamoDB.
Constructor Details
#initialize(opts = {}) ⇒ Connection
Create a connection uri: # default ‘dynamodb.us-east-1.amazonaws.com/’ timeout: # default 5 seconds api_version: # default
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dynamodb/connection.rb', line 21 def initialize(opts = {}) if !(opts[:access_key_id] && opts[:secret_access_key]) raise ArgumentError.new("access_key_id and secret_access_key are required") end set_timeout(opts[:timeout]) if opts[:timeout] @uri = URI(opts[:uri] || "https://dynamodb.us-east-1.amazonaws.com/") region = @uri.host.split(".", 4)[1] || "us-east-1" @api_version = opts[:api_version] || "DynamoDB_20111205" @signer = AWS4::Signer.new( access_key: opts[:access_key_id], secret_key: opts[:secret_access_key], region: region ) end |
Class Method Details
.http_handler ⇒ Object
7 8 9 |
# File 'lib/dynamodb/connection.rb', line 7 def http_handler @http_handler ||= HttpHandler.new end |
.http_handler=(new_http_handler) ⇒ Object
11 12 13 |
# File 'lib/dynamodb/connection.rb', line 11 def http_handler=(new_http_handler) @http_handler = new_http_handler end |
Instance Method Details
#post(operation, body = {}) ⇒ Object
Create and send a request to DynamoDB
This returns either a SuccessResponse or a FailureResponse.
‘operation` can be any DynamoDB operation. `body` is a hash that will be used as the request body (in JSON format). More info available at: docs.amazonwebservices.com/amazondynamodb/latest/developerguide
45 46 47 48 49 50 51 52 53 |
# File 'lib/dynamodb/connection.rb', line 45 def post(operation, body={}) request = DynamoDB::Request.new( signer: @signer, uri: @uri, operation: version(operation), body: body ) http_handler.handle(request) end |