Installation guide
Retrieving items
You can check if the item was added correctly using the getItem() method of the client. Because Amazon
DynamoDB works under an 'eventual consistency' model, we need to specify that we are performing a consistent
read operation.
$result = $client->getItem(array(
'ConsistentRead' => true,
'TableName' => 'errors',
'Key' => array(
'id' => array('N' => '1201'),
'time' => array('N' => $time)
)
));
// Grab value from the result object like an array
echo $result['Item']['id']['N'] . "\n";
//> 1201
echo $result->getPath('Item/id/N') . "\n";
//> 1201
echo $result['Item']['error']['S'] . "\n";
//> Executive overflow
echo $result['Item']['message']['S'] . "\n";
//> no vacant areas
You can also retrieve items in batches of up to 100 using the BatchGetItem() method.
$tableName = 'errors';
$keys = array();
// Given that $keyValues contains a list of your hash and range keys:
// array(array(<hash>, <range>), ...)
// Build the array for the "Keys" parameter
foreach ($keyValues as $values) {
list($hashKeyValue, $rangeKeyValue) = $values;
$keys[] = array(
'id' => array('N' => $hashKeyValue),
'time' => array('N' => $rangeKeyValue)
);
}
// Get multiple items by key in a BatchGetItem request
$result = $client->batchGetItem(array(
'RequestItems' => array(
$tableName => array(
'Keys' => $keys,
'ConsistentRead' => true
)
)
));
$items = $result->getPath("Responses/{$tableName}");
Query and scan
Once data is in an Amazon DynamoDB table, you have two APIs for searching the data: Query and Scan.
Query
A query operation searches only primary key attribute values and supports a subset of comparison operators on key
attribute values to refine the search process. A query returns all of the item data for the matching primary keys (all of
each item's attributes) up to 1MB of data per query operation.
Amazon DynamoDB
68