Class: Fog::AWS::DynamoDB::Real
- Inherits:
-
Object
- Object
- Fog::AWS::DynamoDB::Real
- Includes:
- CredentialFetcher::ConnectionMethods
- Defined in:
- lib/fog/aws/dynamodb.rb,
lib/fog/aws/requests/dynamodb/scan.rb,
lib/fog/aws/requests/dynamodb/query.rb,
lib/fog/aws/requests/dynamodb/get_item.rb,
lib/fog/aws/requests/dynamodb/put_item.rb,
lib/fog/aws/requests/dynamodb/delete_item.rb,
lib/fog/aws/requests/dynamodb/list_tables.rb,
lib/fog/aws/requests/dynamodb/update_item.rb,
lib/fog/aws/requests/dynamodb/create_table.rb,
lib/fog/aws/requests/dynamodb/delete_table.rb,
lib/fog/aws/requests/dynamodb/update_table.rb,
lib/fog/aws/requests/dynamodb/batch_get_item.rb,
lib/fog/aws/requests/dynamodb/describe_table.rb,
lib/fog/aws/requests/dynamodb/batch_write_item.rb
Defined Under Namespace
Classes: DeprecatedAttributeUpdates
Instance Method Summary collapse
-
#batch_get_item(request_items) ⇒ Object
Get DynamoDB items.
- #batch_put_item(request_items) ⇒ Object
-
#batch_write_item(request_items) ⇒ Object
request_items has form:.
-
#create_table(table_name, key_schema, provisioned_throughput) ⇒ Object
Create DynamoDB table.
-
#delete_item(table_name, key, options = {}) ⇒ Object
Delete DynamoDB item.
-
#delete_table(table_name) ⇒ Object
Delete DynamoDB table.
-
#describe_table(table_name) ⇒ Object
Describe DynamoDB table.
-
#get_item(table_name, key, options = {}) ⇒ Object
Get DynamoDB item.
-
#initialize(options = {}) ⇒ Real
constructor
Initialize connection to DynamoDB.
-
#list_tables(options = {}) ⇒ Object
List DynamoDB tables.
-
#put_item(table_name, item, options = {}) ⇒ Object
Update DynamoDB item.
-
#query(table_name, options = {}, hash_key_deprecated = nil) ⇒ Object
Query DynamoDB items.
-
#scan(table_name, options = {}) ⇒ Object
Scan DynamoDB items.
-
#update_item(table_name, key, options = {}, deprecated_attribute_updates = nil) ⇒ Object
Update DynamoDB item.
-
#update_table(table_name, provisioned_throughput) ⇒ Object
Update DynamoDB table throughput.
Methods included from CredentialFetcher::ConnectionMethods
#refresh_credentials_if_expired
Constructor Details
#initialize(options = {}) ⇒ Real
Initialize connection to DynamoDB
Notes
options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection
Examples
ddb = DynamoDB.new(
:aws_access_key_id => your_aws_access_key_id,
:aws_secret_access_key => your_aws_secret_access_key
)
Parameters
-
options<~Hash> - config arguments for connection. Defaults to {}.
Returns
-
DynamoDB object with connection to aws
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/aws/dynamodb.rb', line 74 def initialize(={}) @use_iam_profile = [:use_iam_profile] @region = [:region] || 'us-east-1' setup_credentials() @connection_options = [:connection_options] || {} @instrumentor = [:instrumentor] @instrumentor_name = [:instrumentor_name] || 'fog.aws.dynamodb' @host = [:host] || "dynamodb.#{@region}.amazonaws.com" @path = [:path] || '/' @persistent = [:persistent] || false @port = [:port] || '443' @scheme = [:scheme] || 'https' @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options) end |
Instance Method Details
#batch_get_item(request_items) ⇒ Object
Get DynamoDB items
Parameters
-
‘request_items’<~Hash>:
-
‘table_name’<~Hash>:
-
‘Keys’<~Array>: array of keys
-
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘Responses’<~Hash>:
-
‘table_name’<~Array> - array of all elements
-
-
‘UnprocessedKeys’:<~Hash> - tables and keys in excess of per request limit, pass this to subsequent batch get for pseudo-pagination
-
‘ConsumedCapacity’:<~Hash>:
-
‘TableName’<~String> - the name of the table
-
‘CapacityUnits’<~Float> - Capacity units used in read
-
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fog/aws/requests/dynamodb/batch_get_item.rb', line 24 def batch_get_item(request_items) body = { 'RequestItems' => request_items } request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.BatchGetItem'}, :idempotent => true ) end |
#batch_put_item(request_items) ⇒ Object
5 6 7 8 |
# File 'lib/fog/aws/requests/dynamodb/batch_write_item.rb', line 5 def batch_put_item(request_items) Fog::Logger.deprecation("batch_put_item is deprecated, use batch_write_item instead") batch_write_item(request_items) end |
#batch_write_item(request_items) ⇒ Object
request_items has form:
[{"PutRequest"=>
{"Item"=>
{"hi" => {"N" => 99}
}
}]
}
See DynamoDB Documentation: docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_BatchWriteItems.html
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/aws/requests/dynamodb/batch_write_item.rb', line 22 def batch_write_item(request_items) body = { 'RequestItems' => request_items } request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.BatchWriteItem'} ) end |
#create_table(table_name, key_schema, provisioned_throughput) ⇒ Object
Create DynamoDB table
Parameters
-
‘table_name’<~String> - name of table to create
-
‘key_schema’<~Array>:
* 'AttributeName'<~String> - name of attribute * 'KeyType'<~String> - type of attribute, in %w{N NS S SS} for number, number set, string, string set
-
‘ProvisionedThroughput’<~Hash>:
-
‘ReadCapacityUnits’<~Integer> - read capacity for table, in 5..10000
-
‘WriteCapacityUnits’<~Integer> - write capacity for table, in 5..10000
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘TableDescription’<~Hash>
-
‘CreationDateTime’<~Float> - Unix epoch time of table creation
-
‘KeySchema’<~Array> - schema for table
* 'AttributeName'<~String> - name of attribute * 'KeyType'<~String> - type of attribute, in %w{N NS S SS} for number, number set, string, string set
-
‘ProvisionedThroughput’<~Hash>:
-
‘ReadCapacityUnits’<~Integer> - read capacity for table, in 5..10000
-
‘WriteCapacityUnits’<~Integer> - write capacity for table, in 5..10000
-
-
‘TableName’<~String> - name of table
-
‘TableStatus’<~String> - status of table
-
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/aws/requests/dynamodb/create_table.rb', line 32 def create_table(table_name, key_schema, provisioned_throughput) body = { 'KeySchema' => key_schema, 'ProvisionedThroughput' => provisioned_throughput, 'TableName' => table_name } request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.CreateTable'}, :idempotent => true ) end |
#delete_item(table_name, key, options = {}) ⇒ Object
Delete DynamoDB item
Parameters
-
‘table_name’<~String> - name of table for item
-
‘key’<~Hash> - hash of attributes
Returns
-
response<~Excon::Response>:
-
body<~Hash>: varies based on ReturnValues param, see: docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/aws/requests/dynamodb/delete_item.rb', line 18 def delete_item(table_name, key, = {}) body = { 'Key' => key, 'TableName' => table_name }.merge() request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.DeleteItem'}, :idempotent => true ) end |
#delete_table(table_name) ⇒ Object
Delete DynamoDB table
Parameters
-
‘table_name’<~String> - name of table to delete
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘TableDescription’<~Hash>
-
‘ProvisionedThroughput’<~Hash>:
-
‘ReadCapacityUnits’<~Integer> - read capacity for table, in 5..10000
-
‘WriteCapacityUnits’<~Integer> - write capacity for table, in 5..10000
-
-
‘TableName’<~String> - name of table
-
‘TableStatus’<~String> - status of table
-
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteTable.html
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/aws/requests/dynamodb/delete_table.rb', line 22 def delete_table(table_name) body = { 'TableName' => table_name } request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.DeleteTable'}, :idempotent => true ) end |
#describe_table(table_name) ⇒ Object
Describe DynamoDB table
Parameters
-
‘table_name’<~String> - name of table to describe
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘Table’<~Hash>
-
‘CreationDateTime’<~Float> - Unix epoch time of table creation
-
‘KeySchema’<~Array> - schema for table
-
‘AttributeName’<~String> - name of attribute
-
‘KeyType’<~String> - type of attribute, in %wNS S SS for number, number set, string, string set
-
-
‘ProvisionedThroughput’<~Hash>:
-
‘ReadCapacityUnits’<~Integer> - read capacity for table, in 5..10000
-
‘WriteCapacityUnits’<~Integer> - write capacity for table, in 5..10000
-
-
‘TableName’<~String> - name of table
-
‘TableSizeBytes’<~Integer> - size of table in bytes
-
‘TableStatus’<~String> - status of table
-
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/aws/requests/dynamodb/describe_table.rb', line 27 def describe_table(table_name) body = { 'TableName' => table_name } request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.DescribeTable'}, :idempotent => true ) end |
#get_item(table_name, key, options = {}) ⇒ Object
Get DynamoDB item
Parameters
-
‘table_name’<~String> - name of table for item
-
‘key’<~Hash>:
{ "ForumName": { "S": "Amazon DynamoDB" } }
-
‘options’<~Hash>:
-
‘AttributesToGet’<~Array>: list of array names to return, defaults to returning all
-
‘ConsistentRead’<~Boolean>: whether to wait for updates, defaults to false
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘ConsumedCapacityUnits’<~Float> - Capacity units used in read
-
‘Item’:<~Hash>:
-
‘AttributeName’<~Hash>: in form of “type”:value
-
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/aws/requests/dynamodb/get_item.rb', line 28 def get_item(table_name, key, = {}) body = { 'Key' => key, 'TableName' => table_name }.merge() request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.GetItem'}, :idempotent => true ) end |
#list_tables(options = {}) ⇒ Object
List DynamoDB tables
Parameters
-
‘options’<~Hash> - options, defaults to {}
-
‘ExclusiveStartTableName’<~String> - name of table to begin listing with
-
‘Limit’<~Integer> - limit number of tables to return
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘LastEvaluatedTableName’<~String> - last table name, for pagination
-
‘TableNames’<~Array> - table names
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ListTables.html
20 21 22 23 24 25 26 |
# File 'lib/fog/aws/requests/dynamodb/list_tables.rb', line 20 def list_tables( = {}) request( :body => Fog::JSON.encode(), :headers => {'x-amz-target' => 'DynamoDB_20120810.ListTables'}, :idempotent => true ) end |
#put_item(table_name, item, options = {}) ⇒ Object
Update DynamoDB item
Parameters
-
‘table_name’<~String> - name of table for item
-
‘item’<~Hash>: data to update, must include primary key
"LastPostDateTime": {"S": "201303190422"
}
Returns
-
response<~Excon::Response>:
-
body<~Hash>: varies based on ReturnValues param, see: docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/aws/requests/dynamodb/put_item.rb', line 21 def put_item(table_name, item, = {}) body = { 'Item' => item, 'TableName' => table_name }.merge() request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.PutItem'} ) end |
#query(table_name, options = {}, hash_key_deprecated = nil) ⇒ Object
Query DynamoDB items
Parameters
-
‘table_name’<~String> - name of table to query
-
options<~Hash>:
-
‘AttributesToGet’<~Array> - Array of attributes to get for each item, defaults to all
-
‘ConsistentRead’<~Boolean> - Whether to wait for consistency, defaults to false
-
‘Count’<~Boolean> - If true, returns only a count of such items rather than items themselves, defaults to false
-
‘Limit’<~Integer> - limit of total items to return
-
‘KeyConditionExpression’<~String> - the condition elements need to match
-
‘ExpressionAttributeValues’<~Hash> - values to be used in the key condition expression
-
‘ScanIndexForward’<~Boolean>: Whether to scan from start or end of index, defaults to start
-
‘ExclusiveStartKey’<~Hash>: Key to start listing from, can be taken from LastEvaluatedKey in response
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘ConsumedCapacityUnits’<~Integer> - number of capacity units used for query
-
‘Count’<~Integer> - number of items in response
-
‘Items’<~Array> - array of items returned
-
‘LastEvaluatedKey’<~Hash> - last key scanned, can be passed to ExclusiveStartKey for pagination
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/aws/requests/dynamodb/query.rb', line 29 def query(table_name, = {}, hash_key_deprecated = nil) if hash_key_deprecated || (.keys.length == 1 && [:S, :N, :B].include?(.keys.first.to_sym)) Fog::Logger.deprecation("The `20111205` API version is deprecated. You need to use `KeyConditionExpression` instead of `HashKey`.") apiVersion = '20111205' hash_key = = hash_key_deprecated end body = { 'TableName' => table_name, 'HashKeyValue' => hash_key }.merge() request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => "DynamoDB_#{apiVersion || '20120810'}.Query"} ) end |
#scan(table_name, options = {}) ⇒ Object
Scan DynamoDB items
Parameters
-
‘table_name’<~String> - name of table to query
-
options<~Hash>:
-
‘AttributesToGet’<~Array> - Array of attributes to get for each item, defaults to all
-
‘ConsistentRead’<~Boolean> - Whether to wait for consistency, defaults to false
-
‘Count’<~Boolean> - If true, returns only a count of such items rather than items themselves, defaults to false
-
‘Limit’<~Integer> - limit of total items to return
-
‘KeyConditionExpression’<~String> - the condition elements need to match
-
‘ExpressionAttributeValues’<~Hash> - values to be used in the key condition expression
-
‘ScanIndexForward’<~Boolean>: Whether to scan from start or end of index, defaults to start
-
‘ExclusiveStartKey’<~Hash>: Key to start listing from, can be taken from LastEvaluatedKey in response
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘ConsumedCapacityUnits’<~Integer> - number of capacity units used for scan
-
‘Count’<~Integer> - number of items in response
-
‘Items’<~Array> - array of items returned
-
‘LastEvaluatedKey’<~Hash> - last key scanned, can be passed to ExclusiveStartKey for pagination
-
‘ScannedCount’<~Integer> - number of items scanned before applying filters
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/aws/requests/dynamodb/scan.rb', line 30 def scan(table_name, = {}) body = { 'TableName' => table_name }.merge() request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.Scan'}, :idempotent => true ) end |
#update_item(table_name, key, options = {}, deprecated_attribute_updates = nil) ⇒ Object
Update DynamoDB item
Parameters
-
‘table_name’<~String> - name of table for item
-
‘key’<~Hash> - list of Key attributes
"ForumName": {"S": "Amazon DynamoDB", "Subject": "Maximum number of items?"
}
-
‘options’<~Hash>:
-
‘UpdateExpression’<~String> - the expression that will update the item
-
‘ExpressionAttributeValues’<~Hash> - values to be used in the update expression
-
‘ReturnValues’<~String> - data to return in %w{ALL_NEW ALL_OLD NONE UPDATED_NEW UPDATED_OLD}, defaults to NONE
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>: varies based on ReturnValues param, see: docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/aws/requests/dynamodb/update_item.rb', line 28 def update_item(table_name, key, = {}, deprecated_attribute_updates = nil) if deprecated_attribute_updates raise DeprecatedAttributeUpdates, "The `20111205` DynamoDB API is deprecated. You need to use `ExpressionAttributeValues` instead of `AttributeUpdates`." attribute_updates = = deprecated_attribute_updates.merge( 'AttributeUpdates' => attribute_updates, ) end body = { 'Key' => key, 'TableName' => table_name, }.merge() request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.UpdateItem'} ) end |
#update_table(table_name, provisioned_throughput) ⇒ Object
Update DynamoDB table throughput
Parameters
-
‘table_name’<~String> - name of table to describe
-
‘provisioned_throughput’<~Hash>:
-
‘ReadCapacityUnits’<~Integer> - read capacity for table, in 5..10000
-
‘WriteCapacityUnits’<~Integer> - write capacity for table, in 5..10000
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘Table’<~Hash>
-
‘KeySchema’<~Array> - schema for table
* 'AttributeName'<~String> - name of attribute * 'KeyType'<~String> - type of attribute, in %w{N NS S SS} for number, number set, string, string set
-
‘ProvisionedThroughput’<~Hash>:
-
‘ReadCapacityUnits’<~Integer> - read capacity for table, in 5..10000
-
‘WriteCapacityUnits’<~Integer> - write capacity for table, in 5..10000
-
-
‘TableName’<~String> - name of table
-
‘TableStatus’<~String> - status of table
-
-
-
See DynamoDB Documentation: docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateTable.html
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/aws/requests/dynamodb/update_table.rb', line 28 def update_table(table_name, provisioned_throughput) body = { 'ProvisionedThroughput' => provisioned_throughput, 'TableName' => table_name } request( :body => Fog::JSON.encode(body), :headers => {'x-amz-target' => 'DynamoDB_20120810.UpdateTable'}, :idempotent => true ) end |