Question: How do I create an ID in DynamoDB?

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Answer
DynamoDB has no auto-increment or sequence feature, so it never generates an ID for you. Your application creates the ID and writes it as the partition key, or as part of it.
Pick the kind of ID by what you need from it:
- Random UUID (v4): the default choice. It's unique without coordination and spreads writes evenly across partitions. Use
crypto.randomUUID()in Node.js oruuid.uuid4()in Python. - Time-ordered ID (UUID v7, ULID or KSUID): unique and sortable by creation time. Useful as a sort key, for example to list a customer's orders newest first.
- Sequential number: keep a counter item and increment it atomically with
UpdateItem. Use this only when people need short, ordered numbers such as invoice numbers. Every new ID goes through that one item, and a single item is limited to 1,000 write capacity units per second (fewer writes for larger items), so the counter caps your insert rate. - Natural key: an email address, SKU or ISBN, when it's stable and already unique.
A sequential counter with the AWS SDK for JavaScript v3:
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, UpdateCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const { Attributes } = await ddb.send( new UpdateCommand({ TableName: "Counters", Key: { pk: "invoice" }, UpdateExpression: "ADD seq :one", ExpressionAttributeValues: { ":one": 1 }, ReturnValues: "UPDATED_NEW", }) ); const invoiceNumber = Attributes.seq; // 1, 2, 3, ...
ADD creates the counter on the first call, and concurrent callers each get a different number. Numbers can skip if a request is retried after a timeout, so don't promise a gap-free sequence. Write each new record with ConditionExpression: "attribute_not_exists(pk)" so a bug or retry can never overwrite an existing one.
Generate sample values with the DynamoDB UUID generator, and see increment a counter for more counter code.
Source: AWS DynamoDB documentation.
Other Common DynamoDB FAQ (with Answers)
- Can Power BI connect to DynamoDB?
- What are the naming conventions in DynamoDB?
- Can DynamoDB store blob data?
- Can DynamoDB store documents?
- Can Amazon Data Firehose write to DynamoDB?
- Can you rename a DynamoDB table?
- Can Tableau connect to DynamoDB?
- Is DynamoDB serverless?
- Is DynamoDB a memory store?
- How do you store a graph in DynamoDB?
- Can I use a UUID as a DynamoDB partition key?
- Which programming language works best with DynamoDB?
- What is the maximum number of partitions in DynamoDB?
- Does DynamoDB support Multi-AZ?
- Can DynamoDB store images?
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
- SSH GUI Client
- Chat With Cloud
- MongoDB GUI Client
- AWS Cost Monitoring
- DynamoDB Query Builder
- DynamoDB Code Examples
- DynamoDB Node.js Queries
- DynamoDB JSON Converter
- DynamoDB UUID Generator
- DynamoDB Local Admin GUI
- DynamoDB Pricing Calculator
- DynamoDB Single-Table Design
- Best DynamoDB GUI Clients
- Dynobase vs DynoTable