AWS DynamoDB - Read Data from a Table - GeeksforGeeks

22 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:
{
  "ArticleID": 1,
  "NameofArticle": "DynamoDB"
}

Example 2:
{
  "ArticleID": 3,
  "NameofArticle": "Cloudwatch",
  "Service": "AWS"
}
To read data from a DynamoDB table, there are 3 ways:
get-item – This is used in AWS Command Line Interface (CLI). To retrieve an item you must specify a table name and keys that you want to retrieve.Query – The items in the table can be retrieved by querying on the table. While querying, it by default contains the primary key as a search filter. More attributes can be added to refine search.Scan – It is similar to the query. The only difference is that it doesn’t have any attribute by default for searching. To search an item, you must define an attribute, and its value to find the item.
get-item – This is used in AWS Command Line Interface (CLI). To retrieve an item you must specify a table name and keys that you want to retrieve.
Query – The items in the table can be retrieved by querying on the table. While querying, it by default contains the primary key as a search filter. More attributes can be added to refine search.
Scan – It is similar to the query. The only difference is that it doesn’t have any attribute by default for searching. To search an item, you must define an attribute, and its value to find the item.
Create Table and Items: To read data from a table, the table and data inside the table should exist. In this example, a table named geeksforgeeks has already been created with few items inside it. See the below image:
To read data through Amazon Console we have two ways.
Scan Method: To use the scan method, select Scan from the dropdown. Then in the filter add one attribute. In this example, we want all the articles written by Rohan Chopra. Therefore, add attribute WrittenBy as the filter and enter the value as ‘Rohan Chopra’. Click on start search to get results. See the below image:
Query Method – To use the query method, select Query from the dropdown. By default, we will have our partition key as one search filter. We can add more attributes in the filter to refine our search. In the following image, we see that partition key ArticleID is already present. But we also add one more search filter i.e. Service.
The following image is of the invalid query. The query contains ArticleID=2 and Service=’AWS‘. 
We see that the item ArticleID=2 does not have any attribute as Service. Therefore, no records were found.
Cloud-Computing
Picked
Amazon Web Services
DynamoDB
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install Python3 on AWS EC2?
How to Connect to Amazon Linux Instance from Windows Client Operating System using PUTTY?
Amazon S3 - Cross Region Replication
Amazon EC2 - Creating an Elastic Cloud Compute Instance
AWS DynamoDB - PartiQL Insert Statement
How to Mock AWS DynamoDB Services for Unit Testing?
DynamoDB - Local Installation
AWS DynamoDB - Introduction to DynamoDB Accelerator (DAX)
DynamoDB - Data Types
DynamoDB - Using the Console