-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

DynamoDB Cookbook
By :

In the earlier recipe, we learned how to add new items to the DynamoDB table. In this recipe, we will learn how to query the data that is added using the DynamoDB console.
To perform this recipe, you need to have completed the earlier recipe to add items to the DynamoDB table.
Let's perform different types of queries on AWS DynamoDB console:
id
is 1
, put 1
in the textbox
against the Hash Key, click on the Query button, and you will see the results immediately:phone
, and another with the type book
. Now if we want to fetch the item whose id
is 1
and the type is phone
, then we can query that accordingly, and we will get the results as required:scan
operations in order to fetch the data from the DynamoDB table. We can either do a complete scan or a filtered scan. To perform a complete table scan, we have to select the Scan radio button, and click on the Start New Scan button. As we have not put any filters on the scan, this operation will fetch all the items present in the given DynamoDB table:phone
type, then we can specify the criteria, and execute the scan operation.A
, then we can add this filter and get the results:Query and Scan are powerful operations that help us to retrieve data. However, both have their own working style and their own pros and cons.
A Query
operation finds items in the table using the primary key attributes. You can specify the hash key and optional range key in order to get the desired items. By default, a Query operation returns all the attributes of a given item, but there is an option available to limit the attributes using ProjectionExpressions
. While providing the key conditions, the Query operation expects an equality condition on the Hash Key attribute, but there are a set of conditions allowed to specify the Range Key conditions.
A query request can retrieve a maximum of 1 MB of data at a time. So, you need to plan the Query operation accordingly. You can optionally use FilterExpressions
to narrow down this data. The Hash Key index is an unordered index, which means that we can only specify an exact key to fetch the items, whereas the Range Key index is an ordered index, which allows us to query that index using various ConditionalOperations
, such as less than, greater than, begins with, between, and so on. If no matches are found, Query returns an empty result set.
A Scan operation examines each and every item in the given DynamoDB table, compares it with the condition, and gets the results back. By default, this also returns all the attributes of the items back to the user. Of course, we can use ProjectionExpressions
to limit the set of attributes returned by the scan request.
A single scan request can fetch a maximum of 1 MB of data. To make the best use of it, we can also use FilterExpressions
to narrow down the result set.
There are ways to handle this limitation of 1 MB of data per request, but we cannot do much using the DynamoDB console, so we will talk about all these details in Chapter 2, Operating with DynamoDB Tables.
Change the font size
Change margin width
Change background colour