Error: dynamodb atomic counter not working

Answered by Rafal Wilinski
What's Causing This Error
You may encounter this error when trying to increment a value by using the "+" operator on a document path that does not exist for the item.
Solution - Here's How To Resolve It
To resolve the error, ensure that the document path that you provide exists in DynamoDB. If not, make sure to initialize the document path with a new value. This fix is shown below.
const doFunStuff = async () => {
await documentClient.update({
TableName: 'test-table',
Key: {
pk: '1'
},
UpdateExpression: 'set #count = if_not_exists(#count, :zero) + :incr',
ExpressionAttributeNames: {
'#count': 'count'
},
ExpressionAttributeValues: {
':incr': 1,
':zero': 0
}
}).promise();
};
doFunStuff();
The snippet above uses the if_not_exists() function in DynamoDB that checks if a value exists at the specified document path. If not, it will initialize "0" at the specified document path before incrementing.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB missing items
- dynamodb cannot assign requested address
- Unable to start DynamoDB Local process
- dynamodb-admin command not found
- ConfigError: Missing region in config
- DynamoDB Network Error: self signed certificate in chain
- name key is not defined dynamodb
- why is the GSI dynamodb not showing item count
- dynamodb cannot read property 's' of undefined
- DynamoDB Mapper Could Not Instantiate Class
- an expression attribute name used in the document path is not defined
- DynamoDB Local Docker Not Working
- dynamodb the parameter cannot be converted to a numeric value NaN
- dynamodb cannot read property '0' of undefined
- dynamodb ttl not deleting / erasing items
Tired of switching accounts and regions? Use Dynobase.
First 7 days are on us. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase