dynobase-icon
Dynobase

Question: How do I create an ID in DynamoDB?

Rafal Wilinski

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:

  1. Random UUID (v4): the default choice. It's unique without coordination and spreads writes evenly across partitions. Use crypto.randomUUID() in Node.js or uuid.uuid4() in Python.
  2. 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.
  3. 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.
  4. 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.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Changelog
/
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.