Serverless Developer Guide
• Query – Retrieves all of the items that have a speciﬁc partition key. Within those items, you can 
apply a condition to the sort key and retrieve only a subset of the data. Query provides quick, 
eﬃcient access to the partitions where the data is stored.
• Scan – Retrieves all of the items in the speciﬁed table. This operation should not be used 
with large tables because it can consume large amounts of system resources. Think of it like a 
“SELECT * FROM BIG_TABLE” in SQL. You should generally prefer Query over Scan.
• ExecuteStatement retrieves a single or multiple items from a table.
BatchExecuteStatement retrieves multiple items from diﬀerent tables in a single operation. 
Both of these operations use PartiQL, a SQL-compatible query language.
Primary keys and indexes
• Partition key - also called a hash key, identiﬁes the partition where the data is stored in the 
database.
• Sort key - also called a range key, represents 1:many relationships
The primary key can be a partition key, nothing more. Or, it can be a composite key which is a 
combination of a partition key and sort key. When querying, you must give the partition key, and 
optionally provide the sort key.
Amazon DynamoDB provides fast access to items in a table by specifying primary key values. 
However, many applications might beneﬁt from having one or more secondary (or alternate) keys 
available, to allow eﬃcient access to data with attributes other than the primary key. To address 
this, you can create one or more secondary indexes on a table and issue Query or Scan requests 
against these indexes.
A secondary index is a data structure that contains a subset of attributes from a table, along with 
an alternate key to support Query operations. You can retrieve data from the index using a Query, 
in much the same way as you use Query with a table. A table can have multiple secondary indexes, 
which give your applications access to many diﬀerent query patterns.
DynamoDB supports two types of secondary indexes:
• Global secondary index — An index with a partition key and a sort key that can be diﬀerent 
from those on the base table. A global secondary index is considered "global" because queries 
on the index can span all of the data in the base table, across all partitions. A global secondary 
index is stored in its own partition space away from the base table and scales separately from the 
base table.
Fundamentals 77