AWS DynamoDB - Working with Items & Attributes - GeeksforGeeks

31 Mar, 2021
AWS DynamoDB is a NoSQL managed database that stores semi-structured data i.e. key-value and document data. It stores data in form of an item. An item consists of attributes. Upon table creation in DynamoDB, it only requires a primary key to differentiate between items and no schema is to be defined. Each item can have a different number of attributes. 
Example 1 :
{
  "Color": true,
  "Director": "Christopher Nolan",
  "MovieID": 1,
  "Name": "Inception",
  "Rating": 8.7,
  "Year": 2010
}
Example 2:
{
  "Color": false,
  "MovieID": 99,
  "Name": "Schindler's List"
}
In the above examples, two different items have been shown. We observe that each item contains a different number of attributes. One attribute MovieID should always be present in each item and its value cannot be the same in two items as it is the primary key.
 To create items, first, we must create a table in DynamoDB with a partition key. A table named Movies has already been created with MovieID as our partition key. See the below image:
 Navigate to the Items tab of the table, and click Create items to add items to the table. Items can be added via Tree format or via text. Both of them have been shown below:
Create Item
Tree Format
Tree Format
In the above items, one attribute MovieID will always be present. Rest of the attributes, either you can add or delete from the item.
To write an item to a table, there are two ways. Either we can add items to the table via Amazon CLI (Command Line Interface) or via the Amazon Management Console. To write items, first create a table and once it is created, simply navigate to the Items tab of the table and click Create Item. Specify the attributes and their value and then click Save. This will write items to the table.
For more information visit. 
Reading an item from a table can be done using three ways. These are get-item, Query, and Scan. Query and scan methods are used for Amazon Management Console and the get-item method is used when we are trying to read data from a table using Amazon CLI (Command Line Interface).  
For more information refer to this. 
In batch operations, you either write or read multiple items from the Dynamodb table using PartiQL. The two operations are given below :
BatchGetItem: To read multiple items. It can read about 100 items from one or more tables.
BatchWriteItem: To create or delete items. It can either write or delete up to 25 items from one or more tables.
To implement an atomic counter, use the UpdateItem operation. The atomic counter is a numeric attribute that is incremented, unconditionally, without interfering with other write requests i.e. all write requests are implemented in the order in which they were received. The numeric value increments each time you call UpdateItem. For instance, we can use the atomic counter to track the visitors to a website. Each time a user hits our website, the counter gets incremented.
By default, the DynamoDB overwrites the existing item that has specified primary key on PutItem, UpdateItem, and DeleteItem operation requests. To solve this problem, DynamoDB provides a feature of conditional writes. A conditional write will only succeed if some criteria are met. For example, the PutItem request will only succeed if there is no item present with the same primary key or could prevent from overwriting an existing item if requirements are met. 
AWS
Cloud-Computing
Picked
Amazon Web Services
DynamoDB
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Amazon S3 - Storage Classes
Amazon EC2 - Creating an Elastic Cloud Compute Instance
AWS DynamoDB - PartiQL Insert Statement
Amazon S3 - Cross Region Replication
AWS DynamoDB - PartiQL Delete Statements For DynamoDB
How to Mock AWS DynamoDB Services for Unit Testing?
DynamoDB - Local Installation
DynamoDB - Data Types
AWS DynamoDB - Web Based Setup
AWS DynamoDB - Introduction to DynamoDB Accelerator (DAX)