Modifying Data

Inserting Data

The DynamoDB PutItem API is used to create a new item or to replace existing items completely with a new item. It is invoked using the put-item CLI command.

Let’s say we wanted to insert a new item into the Reply table from the console. First, navigate to the Reply table click the Create Item button.

Console Create Item 1

You will need to click Add new attribute a couple of times to make some new String attributes, and then fill in the following data, then click Create Item.

        "Id" : "Amazon DynamoDB#DynamoDB Thread 2",
        "ReplyDateTime" : "2021-04-27T17:47:30Z",
        "Message" : "DynamoDB Thread 2 Reply 3 text",
        "PostedBy" : "User C"

Console Create Item 2

Updating or Deleting Data

The DynamoDB UpdateItem API is used to create a new item or to replace existing items completely with a new item. It is invoked using the update-item CLI command. This API requires you to specify the full Primary Key and can selectively modify specific attributes without changing others(you don’t need to pass in the full item).

The DynamoDB DeleteItem API is used to create a new item or to replace existing items completely with a new item. It is invoked using the delete-item CLI command.

You can easily modify or delete an item using the console by selecting the checkbox next to the item of interest, clicking the Actions dropdown and performing the desired action.

Console Delete Item

Exercise

Update the ProductCatalog item where Id=201 to add new colors “Silver” and “Green” to the list of colors for that bike type. Then use the Item Editor again to remove those “Silver” and “Green” list entries to return it to the original state.

The solution is expandable below but try to figure it out yourself before moving forward.

Click below to expand and see the exercise solutions

Expand this to see the solution