In this module, you walk through some simple examples of retrieving multiple items in one API call with DynamoDB. You also learn how to use secondary indexes to enable additional query patterns on your DynamoDB tables.
Time to Complete Module: 15 Minutes
In Module 2, you saw how to retrieve a single book from a DynamoDB table by using the GetItem API call. This access pattern is useful, but your application also needs to be able to retrieve multiple items in one call. For example, you may want to retrieve all books that were written by John Grisham so that you can display them to users. In Step 1 in this module, you use the Query API to retrieve all books by a specific author.
Both the GetItem API call to get a single book and the Query API call to retrieve all books by an author use the specified primary key on your Books table. However, you may want to enable additional access patterns, such as retrieving all books in a particular category such as history or biography. Category is not part of your table’s primary key, but you can create a secondary index to allow for additional access patterns. You will create a secondary index and query the secondary index in Steps 2 and 3 of this module.