DynamoDB UpdateItem with the AWS CLI

aws dynamodb update-item changes specific attributes of one item (and creates it if absent), leaving everything else untouched. The change is expressed with --update-expression and DynamoDB-JSON values.

Code

aws dynamodb update-item \
  --table-name Music \
  --key '{
    "Artist":    {"S": "Arturo Sandoval"},
    "SongTitle": {"S": "Cubano Chant"}
  }' \
  --update-expression "SET Genre = :genre, #yr = :year ADD Awards :inc" \
  --expression-attribute-names '{"#yr": "Year"}' \
  --expression-attribute-values '{
    ":genre": {"S": "Latin Jazz"},
    ":year":  {"N": "1994"},
    ":inc":   {"N": "1"}
  }' \
  --return-values ALL_NEW \
  --region us-east-1

With --return-values ALL_NEW the command prints the item after the update:

{
  "Attributes": {
    "Artist": {"S": "Arturo Sandoval"},
    "SongTitle": {"S": "Cubano Chant"},
    "Genre": {"S": "Latin Jazz"},
    "Year": {"N": "1994"},
    "Awards": {"N": "1"}
  }
}

Explanation

  • --key — the full primary key of the item to update, in DynamoDB JSON.
  • --update-expression — one or more clauses:
    • SET assigns attributes (Genre = :genre). Year is reserved, so it's aliased through --expression-attribute-names.
    • ADD on a number is an atomic increment (ADD Awards :inc). REMOVE deletes an attribute; DELETE removes set elements.
  • --expression-attribute-values — the :placeholder → typed-value map in DynamoDB JSON.
  • --return-valuesALL_NEW prints the item after the update (also UPDATED_NEW, ALL_OLD, UPDATED_OLD, NONE).
  • Upsert semanticsupdate-item creates the item if the key doesn't exist. Add --condition-expression "attribute_exists(Artist)" to update-only.

Do it visually

The DynamoDB Expression Builder builds SET / ADD / REMOVE clauses with the name/value JSON and hands you a copy-paste CLI command.

To edit items in a GUI — change a field, review the generated UpdateExpression, copy-as-CLI — download DynoTable.

Mit DynamoDB ohne die Console arbeiten

DynoTable ist ein schneller Desktop-Client für DynamoDB — durchsuche Tabellen, führe SQL-artige Queries aus und bearbeite Items lokal.