Installation guide
array(
'PutRequest' => array(
'Item' => array(
'CustomerId' => array('N' => 941),
'OrderId' => array('N' => 3),
'OrderDate' => array('N' => strtotime('-1 days')),
'ItemId' => array('N' => 25336)
)
)
)
)
)
));
When you query the table with an LSI, you must specify the name of the index using the IndexName parameter.
The attributes that are returned will depend on the value of the Select parameter and on what the table is
projecting to the index. In this case 'Select' => 'COUNT' has been specified, so only the count of the items will
be returned.
// Find the number of orders made by customer 941 in the last 10 days
$result = $client->query(array(
'TableName' => 'Orders',
'IndexName' => 'OrderDateIndex',
'Select' => 'COUNT',
'KeyConditions' => array(
'CustomerId' => array(
'AttributeValueList' => array(
array('N' => '941')
),
'ComparisonOperator' => 'EQ'
),
'OrderDate' => array(
'AttributeValueList' => array(
array('N' => strtotime("-10 days"))
),
'ComparisonOperator' => 'GE'
)
)
));
$numOrders = $result['Count'];
Using the WriteRequestBatch
You can use the WriteRequestBatch if you need to write or delete many items as quickly as possible. The
WriteRequestBatch provides a high level of performance because it converts what would normally be a separate
HTTP request for each operation into HTTP requests containing up to 25 comparable requests per transaction.
If you have a large array of items you wish to add to your table, you could iterate over the them, add each item to the
batch object. After all the items are added call flush(). The batch object will automatically flush the batch and
write items to Amazon DynamoDB after hitting a customizable threshold. A final call to the batch object's flush()
method is necessary to transfer any remaining items in the queue.
$tableName = 'batch-write-test'; // This table has a HashKey named "id"
$itemIds = array();
// Put 55 items into the table
$putBatch = WriteRequestBatch::factory($client);
for ($i = 0; $i < 55; $i++) {
$itemIds[] = $itemId = uniqid();
$item = Item::fromArray(array(
Amazon DynamoDB
72