dynobase-icon
Dynobase

DynamoDB: Increment Counter (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

Last updated: October 23rd, 2026

Use ADD on a Number attribute to increment it atomically and return the updated value. A missing counter starts at zero; the request can create the item if the key is absent.

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, UpdateCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const { Attributes } = await ddb.send(new UpdateCommand({ TableName: "Orders", Key: { pk: "COUNTER", sk: "ORDERS" }, UpdateExpression: "ADD #value :one", ExpressionAttributeNames: { "#value": "value" }, ExpressionAttributeValues: { ":one": 1 }, ReturnValues: "UPDATED_NEW", })); console.log(Attributes?.value);

An increment is not idempotent. Retrying after an ambiguous timeout can increment twice. Use an idempotency record or conditional transaction for exactly-once business effects.

Reference: AWS UpdateItem 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
/
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.