I have a table called products with primary key Id. I want to select all items in the table. This is the code is I’m using:
$batch_get_response = $dynamodb->batch_get_item(array(
'RequestItems' => array(
'products' => array(
'Keys' => array(
array( // Key #1
'HashKeyElement' => array( AmazonDynamoDB::TYPE_NUMBER => '1'),
'RangeKeyElement' => array( AmazonDynamoDB::TYPE_NUMBER => $current_time),
),
array( // Key #2
'HashKeyElement' => array( AmazonDynamoDB::TYPE_NUMBER => '2'),
'RangeKeyElement' => array( AmazonDynamoDB::TYPE_NUMBER => $current_time),
),
)
)
)
));
Is it possible to select all items without specifying the primary key? I’m using the AWS SDK for PHP.
Amazon DynamoDB provides the Scan operation for this purpose, which returns one or more items and its attributes by performing a full scan of a table. Please be aware of the following two constraints:
Depending on your table size, you may need to use pagination to retrieve the entire result set:
The Scan operation is potentially costly regarding both performance and consumed capacity units (i.e. price), see section Scan and Query Performance in Query and Scan in Amazon DynamoDB:
You can find more details about this operation and some example snippets in Scanning Tables Using the AWS SDK for PHP Low-Level API for Amazon DynamoDB, with the most simple example illustrating the operation being: