DynamoDB: Increment Counter (Guide w/ Code Examples)

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.
Similar Code Examples
- DynamoDB: Query Greater Than
- DynamoDB: Query Date Range
- DynamoDB: Get By ID
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: Get Unique Values
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Get Last 10 Records
- DynamoDB: Attribute Not Null
- DynamoDB: Not Begins With
- DynamoDB: Get All Items
- DynamoDB: Bulk Insert
- DynamoDB: Query Group By
- DynamoDB: Delete Table
- DynamoDB: Get Last Inserted Item
- DynamoDB BatchWriteItem in Typescript
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