Open In App

AWS DynamoDB – Update Data in a Table

Last Updated : 28 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Amazon DynamoDB is a NoSQL managed database that supports semi-structured data i.e. key-value and document data. A DynamoDB table stores data in the form of an item. While creating a table in DynamoDB, a partition key needs to be defined which acts as the primary key for the table and no schema. Each item consists of attributes. By default, every item will have a partition key as one of the attributes. Every item can have a different number of attributes. An example of an item is given below:

Example:
{
  "Color": true,
  "Director": "Christopher Nolan",
  "MovieID": 1,
  "Name": "Inception",
  "Rating": 8.7,
  "Year": 2010
}

We will be doing the following operations in this article:

  1. Create a table in DynamoDB, say, Movies.
  2. Add items or data into the table.
  3. Update attribute of an item in the table.

The above approach has been implemented below:

Create Table and add Data :

  • Create a table named Movies with partition key as MoviesID. Add items to the table. A table has been already created for your reference. See the image below:

Update Data:

 There are two ways to update the attributes of an item. They are :

  • AWS CLI – In this, update-item is used to update the value of an attribute using Amazon Command Line Interface (CLI).
  • Amazon Management Console – To update the value of an attribute in items, navigate to the Items tab of a table and click on the MovieID to update the item. An edit item page will open to either add, update or delete a key-value pair. In the original table, the director column of MovieID=050 is empty. We are going to add ‘Christopher Nolan’ under the director attribute. See the below images:

Edit MovieID 050

Updated Table 

We observe that the director column of MovieID=050 has been updated with the value ‘Christopher Nolan’. Similarly, we can select any partition key and edit the value of the attribute of an item.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads