Step 4: Update data in a table - Amazon DynamoDB
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Step 4: Update data in a table

In this step, you update an item that you created in Step 2: Write data to a table using the console or Amazon CLI. You can use the DynamoDB console or the Amazon CLI to update the AlbumTitle of an item in the Music table by specifying Artist, SongTitle, and the updated AlbumTitle.

For more information about write operations, see Writing an item.

You can use the DynamoDB console to update data in the Music table.

  1. Open the DynamoDB console at https://console.amazonaws.cn/dynamodb/.

  2. In the left navigation pane, choose Tables.

  3. Choose the Music table from the table list.

  4. Choose Explore table items.

  5. In Items returned, for the item row with Acme Band Artist and Happy Day SongTitle, do the following:

    1. Place your cursor on the AlbumTitle named Songs About Life.

    2. Choose the Edit icon.

    3. In the Edit String popup window, enter Songs of Twilight.

    4. Choose Save.

    Tip

    Alternatively, to update an item, do the following in the Items returned section:

    1. Choose the item row with Artist named Acme Band and SongTitle named Happy Day.

    2. From the Actions dropdown list, choose Edit item.

    3. For enter AlbumTitle, enter Songs of Twilight.

    4. Choose Save and close.

The following Amazon CLI example updates an item in the Music table. You can do this either through the DynamoDB API or PartiQL, a SQL-compatible query language for DynamoDB.

DynamoDB API

Linux

aws dynamodb update-item \ --table-name Music \ --key '{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}}' \ --update-expression "SET AlbumTitle = :newval" \ --expression-attribute-values '{":newval":{"S":"Updated Album Title"}}' \ --return-values ALL_NEW

Windows CMD

aws dynamodb update-item ^ --table-name Music ^ --key "{\"Artist\": {\"S\": \"Acme Band\"}, \"SongTitle\": {\"S\": \"Happy Day\"}}" ^ --update-expression "SET AlbumTitle = :newval" ^ --expression-attribute-values "{\":newval\":{\"S\":\"Updated Album Title\"}}" ^ --return-values ALL_NEW

Using update-item returns the following sample result because return-values ALL_NEW was specified.

{ "Attributes": { "AlbumTitle": { "S": "Updated Album Title" }, "Awards": { "S": "10" }, "Artist": { "S": "Acme Band" }, "SongTitle": { "S": "Happy Day" } } }
PartiQL for DynamoDB

Linux

aws dynamodb execute-statement --statement "UPDATE Music \ SET AlbumTitle='Updated Album Title' \ WHERE Artist='Acme Band' AND SongTitle='Happy Day' \ RETURNING ALL NEW *"

Windows CMD

aws dynamodb execute-statement --statement "UPDATE Music SET AlbumTitle='Updated Album Title' WHERE Artist='Acme Band' AND SongTitle='Happy Day' RETURNING ALL NEW *"

Using the Update statement returns the following sample result because RETURNING ALL NEW * was specified.

{ "Items": [ { "AlbumTitle": { "S": "Updated Album Title" }, "Awards": { "S": "10" }, "Artist": { "S": "Acme Band" }, "SongTitle": { "S": "Happy Day" } } ] }

For more information about updating data with PartiQL, see PartiQL update statements.

To query the data in the Music table, proceed to Step 5: Query data in a table.