dynobase-icon
Dynobase

Question: Can DynamoDB have duplicates?

Rafal Wilinski

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 email or city. 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 Query on 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.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.