Amazon DynamoDB is a non-relational Database (NoSQL) service.
DynamoDB uses tables, items, and attributes. See here for more information.
A table is a collection of items and each item is a collection of attributes.
Each attribute can be scalar (for example, of String or Number type), vector (for example, sets of String or Number type), or document (for example, an ordered set of data of different types).
The primary key uniquely identifies each item in the table, so that no two items can have the same key.
DynamoDB uses primary keys to uniquely identify each item in the table.
The primary key must be scalar and of String, Number or Binary type.
DynamoDB supports two types of primary keys:
- Partition key: A simple primary key, composed of one attribute known as the partition key.
- Partition key and sort key: Referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key.
DynamoDB uses indexes called secondary indexes to provide flexibility in queries.
Secondary indexes are a structure that contains a subset of attributes of a table.
When you create an index, you must keep in mind that: it only belongs to one table (called the base table for the index) and you must specify which attributes from the base table will be copied to the index. Any data change made to the base table will automatically be reflected in the indexes.
You can define secondary indexes of two types:
Global secondary index – An index with a partition key and sort key that can be different from those on the table.
Local secondary index – An index that has the same partition key as the table, but a different sort key.
The following image shows the Attraction table containing some examples of elements and attributes. The primary key consists of two attributes (Name and City). The combination of Name and City sets each element in the table apart from all the others.
Note: If the primary key is composite, the partition key and sort key fields must be filled.
The following image shows a general secondary index of the Attraction table called CategoryAttraction. In this index, Category is the partition key.
DynamoDB copies, in the index, the primary key of the base table; in this case, it is Name and City.
You can query the CategoryAttraction index to find all attractions in a given category.
The following table compares the terms used in DynamoDB with the terms used in SQL Databases.
||Global secondary index