accesspatterns.dev

Writing data · Lesson 9 of 20

UpdateItem edits in place

UpdateItem changes named attributes and can increment a counter atomically.

Next · Writing dataClaim it, or fail

Why

UpdateItem changes the attributes you name and leaves everything else alone. SET assigns a value; ADD increments a number atomically on the server, so two concurrent increments can never lose each other.

Rename the playlist, then count a play twice and watch plays climb. Note name uses an ExpressionAttributeNames placeholder because some attribute names are reserved words.

UpdateItem edits in place. ADD gives you atomic counters with no read-modify-write race.

Playlists
Try an example

SET changes one attribute and leaves the rest of the META item untouched.

pk(pk)
sk(sk)
name
owner
title
seconds

Run an operation to see the raw engine response.

table Playlistskeys pk / skitems 26