Amazon DynamoDB: Core Components
In this article, we will be discussing the core components of DynamoDB as well as looking at its features.
Join the DZone community and get the full member experience.
Join For FreeThis article was first published on the Knoldus blog.
DynamoDB is a part of Amazon Web Services. It is a NoSQL database, which supports key-value and document data structures.
In this article, we will be discussing the core components of DynamoDB.
Features of DynamoDB
- It is a fully managed NoSQL database.
- It can store and retrieve any amount of data and can serve any amount of traffic.
- To maintain fast performance, it distributes data and traffic over servers.
- It provides a provisioned-throughput model through which read and write units can be changed at any time according to the requirement of the application.
- Using Amazon's IAM (Identity and Access Management) service, we can apply security and access control over the database.
Core Components of DynamoDB
The core components of DynamoDb are Tables, Attributes, and Items.
Table
- In DynamoDb, Data is stored in tables in the form of items.
Items
Every Item in DynamoDb is like a row, tuple or record of any other Database system.
- Item is a collection of attributes.
- Each item can have its own distinct attributes.
- A table can have 0 or more items.
- We can store as many items as we want, there is no limit.
Attributes
Attributes are the fundamental elements of an item that require no further decomposition. They store information in the form of key-value pairs.
- Attributes are like columns of other database systems.
- We don't need to define the attributes or their data types beforehand.
- We only need to define the Primary key.
- DynamoDB supports nested attributes up to 32 levels deep.
DynamoDB supports the following data types:
- Scalar — Number, String, Binary, Boolean, and Null.
- Multi-valued — String Set, Number Set, and Binary Set.
- Document — List and Map.
Example 1
A table named Minion with sample items and attributes.

Things to Notice in the Minion Table
- Each item has a unique identifier (Primary key).
- In the Minion table, the primary key consists of one attribute (ID).
- Other than primary keys, the Minion table is Schemaless.
- Nested attribute (traits).
Example 2
Table Movie with sample items and attributes.

Things to Notice in the Movie Table
- The primary key for Movie consists of two attributes (Director and MovieName).
- Each item in the table must have these two attributes.
- The combination of Director and MovieName distinguishes each item in the table from all of the others.
Primary Key
Primary key is used to uniquely identify an item in a table.
DynamoDB supports two different types of primary keys:
- Partition Key
- Partition-Sort key (Composite primary key).
Partition Key
In this case, a primary key consists of a single attribute known as the partition key. It is also known as Hash attribute of an item.
DynamoDB uses an internal hash function to determine the partition (physical storage internal to DynamoDB) where the item is stored. The input to this hash function is the partition key's value.
In a table or a Secondary Index, that has only one partition key, no two items can have the same partition key value. There is no limit on the number of distinct values of partition key. But there is a limit on its length i.e. minimum length of the value of partition key could be 1 byte and the maximum is 2048 bytes.
Partition-Sort Key
In this case, a primary key consists of two attributes i.e. Partition key and Sort key.
The values of two partition keys could be the same, but the values of sort key must be different.
All items with the same partition key values are sorted by sort key value and are stored together in the same partition.
By using both the values of an item together (Patition key and Sort key), we can access any item in the table.
e.g. In the table Movie, if we provide only the value of Director, DynamoDB retrieves all the movies by that director.
Points to Remember
- The sort key is also known as Range attribute of an item. The term range attribute derives from the way DynamoDB stores items with the same partition key physically close together, in sorted order by the sort key value.
- Each primary key attribute must be a scalar (meaning that it can hold only a single value).
- The only data types allowed for primary key attributes are the string, number, or binary.
- If the sort key is well defined, it can be very helpful, One can use operators like starts-with, between, >, <, etc.
I hope you liked this article. Let me know your thoughts in the comments section.
References
Amazon DynamoDb developer guide.This article was first published on the Knoldus blog.
Published at DZone with permission of Nancy Jain, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments