The primary key uniquely identifies each item in the table. Two items in a table cannot have the same primary key value. Even if DynamoDB tables are schemaless, we have to define a primary key attribute while creating the table. A null value is not applicable for the primary key attribute value. The following figure represents items in the Person table. Here, PersonID is a primary key that uniquely identifies each Person item in the table:

DynamoDB supports two kinds of primary key: the partition key and the composite primary key, which is a combination of the partition key and the sort key. Let us discuss both keys in detail:
- Partition key: With the partition key, we only have to use one attribute as the primary key, which is known as a partition key. DynamoDB uses the partition key to determine the partition (physical location) in which to store the item. For example, if our internal hash function is the mod function, then the item with PersonID 101 will be stored in partition 1, as 101 % 100 = 1, in the same way, the item with PersonID 102 will be stored in partition 2:

This will make the retrieval of data very much faster. We can immediately access the item by giving the partition key. We can create a partition key while creating a table by choosing the key attribute, as shown in the following screenshot:

- Composite primary key: The composite primary key has two attributes. The first attribute is used as a partition key and the second attribute is used as a sort key. The partition key is used to determine the partition of the item. If two items have the same hash output, they are stored in the single partition. The sort key is used to determine the order of the item in a partition if two or more items receive the same partition. For example, say that we have PersonID 101, 102 already stored in the partition, and if we now insert an item with PersonID 201, we will get partition 1. As we defined age as the sort key item, 201 will be inserted before 101 as its age is less than 23. In a composite primary key, we can have two items with the same partition key, but the sort key must be different. The partition key in DynamoDB is also called a hash attribute as it is used by the hash function. Partition key values must be scalar values. String, number, and binary are the only data types allowed for a primary key. To create a composite key, we can add a sort key while creating the table:
