Question: Can DynamoDB have duplicates?

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Answer
No, not for the primary key. Every item's primary key (the partition key, or the partition key plus sort key) is unique within the table. Writing an item whose key already exists doesn't create a second copy: PutItem replaces the whole existing item, and UpdateItem modifies it.
Everything that isn't the primary key can repeat:
- Non-key attributes. Any number of items can have the same
emailorcity. DynamoDB doesn't enforce uniqueness on other attributes. - Partition keys in a composite key. Many items can share a partition key as long as their sort keys differ.
- Index keys. Global and local secondary indexes don't enforce uniqueness, so a
Queryon an index can return many items with the same key values. - Lists. A List can hold the same value twice. Sets (String, Number and Binary sets) never contain duplicate values.
To stop a write from silently overwriting an existing item, add a condition:
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); await ddb.send( new PutCommand({ TableName: "Users", Item: { pk: "USER#123", email: "ana@example.com" }, ConditionExpression: "attribute_not_exists(pk)", }) );
If an item with that key exists, the call fails with ConditionalCheckFailedException instead of replacing it.
To make a non-key attribute unique, such as an email address, write a second "guard" item whose primary key is that value (pk = EMAIL#ana@example.com) in the same TransactWriteItems call, with attribute_not_exists(pk) on both items. The transaction fails if either key already exists, so two users can never claim the same email. For more patterns, see create an item only if it doesn't exist.
Source: AWS DynamoDB documentation.
Other Common DynamoDB FAQ (with Answers)
- Is DynamoDB a memory store?
- What are the key differences between DynamoDB and Elasticsearch?
- Are DynamoDB table names unique?
- Is DynamoDB ACID compliant?
- Is DynamoDB open source?
- How to import data from S3 to DynamoDB?
- Can DynamoDB store blob data?
- Does DynamoDB have read replicas?
- How to count rows in DynamoDB?
- Can DynamoDB store images?
- Can you make a DynamoDB table case-insensitive?
- Can you force-delete a DynamoDB table?
- Can DynamoDB have null values?
- How do you dump multiple DynamoDB tables?
- What does DynamoDB Query return?
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today