dynobase-icon
Dynobase

DynamoDB: Get Unique Values (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

Last updated: October 23rd, 2026

DynamoDB has no DISTINCT operation for arbitrary attributes. Scan projected values and deduplicate them in your application, or maintain a separate lookup item for each value at write time.

Install @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb, use an ES module on a supported Node.js runtime, and configure an AWS Region and credentials. The examples use an existing Orders table with String keys pk and sk unless an index or timestamp key is described.

import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const regions = new Set(); let lastKey; do { const page = await ddb.send(new ScanCommand({ TableName: "Orders", ProjectionExpression: "#region", ExpressionAttributeNames: { "#region": "region" }, ExclusiveStartKey: lastKey, })); for (const item of page.Items ?? []) { if (typeof item.region === "string") regions.add(item.region); } lastKey = page.LastEvaluatedKey; } while (lastKey && Object.keys(lastKey).length > 0); console.log([...regions]);

Projection reduces response payload, not read capacity. This example assumes region is a String; the set consumes memory proportional to the number of distinct values.

Reference: AWS Scan API. For related access patterns, see DynamoDB query examples.

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.