Installation guide
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(
'HashKeyElement' => array('N' => $hashKeyValue),
'RangeKeyElement' => 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.
Let's say we want a list of all "1201" errors that occurred in the last 15 minutes. We could issue a single query that
will search by the primary key of the table and retrieve up to 1MB of the items. However, a better approach is to use
the query iterator to retrieve the entire list of all items matching the query.
$iterator = $client->getIterator('Query', array(
'TableName' => 'errors',
'HashKeyValue' => array('N' => '1201'),
'RangeKeyCondition' => array(
'AttributeValueList' => array(
array('N' => strtotime("-15 minutes"))
),
'ComparisonOperator' => 'GT'
)
));
// Each item will contain the attributes we added
foreach ($iterator as $item) {
// Grab the time number value
echo $item['time']['N'] . "\n";
// Grab the error string value
Amazon DynamoDB (2011-12-05)
77