DynamoDB UpdateItem in Node.js (AWS SDK v3)
UpdateItem changes specific attributes of one item (and creates the item if it doesn't exist), leaving everything else untouched. In AWS SDK v3 you send an UpdateItemCommand with an UpdateExpression.
Code
import {DynamoDBClient, UpdateItemCommand} from '@aws-sdk/client-dynamodb';
const client = new DynamoDBClient({region: 'us-east-1'});
const command = new UpdateItemCommand({
TableName: 'Music',
Key: {
Artist: {S: 'Arturo Sandoval'},
SongTitle: {S: 'Cubano Chant'}
},
UpdateExpression: 'SET #upd0 = :updValue0, #upd1 = :updValue1 ADD #upd2 :updValue2',
ExpressionAttributeNames: {
'#upd0': 'Genre',
'#upd1': 'Year',
'#upd2': 'Awards'
},
ExpressionAttributeValues: {
':updValue0': {S: 'Latin Jazz'},
':updValue1': {N: '1994'},
':updValue2': {N: '1'}
},
ReturnValues: 'ALL_NEW'
});
const response = await client.send(command);
console.log(response.Attributes); // the item after the updateExplanation
Key— the full primary key of the item to update.UpdateExpression— one or more clauses:SETassigns attributes (#upd0 = :updValue0setsGenre;#upd1 = :updValue1setsYear). Every attribute is aliased viaExpressionAttributeNames, so reserved words likeYearare always safe.ADDon a number does an atomic increment (ADD #upd2 :updValue2adds 1 toAwards) — safe under concurrency, no read-modify-write race.REMOVEdeletes an attribute;DELETEremoves elements from a set.
ExpressionAttributeValues— the:placeholder→ typed-value map.ReturnValues—"ALL_NEW"returns the full item after the update (alsoUPDATED_NEW,ALL_OLD,UPDATED_OLD, orNONE).- Upsert semantics —
UpdateItemcreates the item if the key doesn't exist. Add aConditionExpression(e.g.attribute_exists(Artist)) to update-only.
Do it visually
The DynamoDB Expression Builder builds SET / ADD / REMOVE clauses with the name/value maps and copies runnable code.
To edit items in a GUI — change a field, review the generated UpdateExpression, copy the SDK v3 code — download DynoTable.
Related guides
- DynamoDB update expressions —
SET,ADD,REMOVE,DELETE, and idioms. - Understanding ReturnValues — what each
ReturnValuesoption gives you. - "Attribute name is a reserved keyword" — why the alias map here isn't optional.
- "Invalid UpdateExpression" syntax errors — the common SET/ADD syntax mistakes, decoded.
References
- UpdateItem — Amazon DynamoDB API Reference
- UpdateItemCommand — AWS SDK for JavaScript v3 Reference
- Update expressions — Amazon DynamoDB Developer Guide
Last verified 2026-07-13 against the official AWS documentation linked above.