#5 My Whizlabs Lab Journey - Introduction to DynamoDB
Introduction
DynamoDB is a fast and flexible NoSQL database designed for applications that need consistent, single-digit millisecond latency at any scale. It is a fully managed database, and it supports both document and key-value data models.
It has a very flexible data model. This means that you don't need to define your database schema upfront. It also has reliable performance.
DynamoDB is a good fit for mobile gaming, ad-tech, IoT and many other applications.
DynamoDB Tables
DynamoDB tables consist of
Items (Think of a row of data in a table).
Attributes (Think of a column of data in a table).
Supports key-value and document data structures.
Key= the name of the data, Value= the data itself.
The document can be written in JSON, HTML, or XML.
DynamoDB- Primary Keys
DynamoDB stores and retrieves data based on a Primary key
DynamoDB also uses Partition keys to determine the physical location data is stored.
If you are using a partition key as your Primary key, then no items will have the same Partition key.
Composite Keys (Partition Key + Sort Key) can be used in Combination.
Two items may have the same partition key, but must have a different sort key.
All items with the same partition key are stored together and then sorted according to the sort key value.
DynamoDB allows you to store multiple items with the same partition keys.
In this beginner-level lab journey, we will create a DynamoDB Table, insert data into the DynamoDB Table and Search for an Item in the DynamoDB Table.
Let's get started!
Task 1: Create DynamoDB Table
In this task, we are going to create a DynamoDB table.
Navigate to DynamoDB page by clicking on the Services menu at the top. DynamoDB is available under the Database section.
Click on Create table button
Set the Table Name: Enter mydynamodbtable
Set the Primary key: Enter companyid and select Number
Add the sort key: Enter name in the respective field and select String.
The combination of a Primary Key and a Sort Key uniquely identifies each item in a DynamoDB table.
Leave all the other settings as default and then click on Create table.
Your table will be created within 2–3 minutes, once the table is created, 5. the Status will change to Active as indicated on the screen below
Task 3: Inserting Data into DynamoDB Table
In this task, we will insert data into a DynamoDB table. By adding data to the table, we will understand how to populate it with relevant information.
Next, we are inserting data in the table we created.
Select mydynamodbtable and then Click on the Explore table items button.
Click on Create item button.
Add new primary key and sort key values.
companyid: 1
name: Kevin
Add 4–5 items as shown in the above step, and the result will be similar to the screen below:
Task 4 : Search for Items in the Table
In this task, we will demonstrate the query capabilities of DynamoDB by using the query operation.
Select Query
In the query window, enter the partition key and sort key which you want to search.
Partition Key = 4
Sort Key = Jane
Click on Run.
You will be able to see a result table with your filtered records as shown below:
You can also query using only the partition key in this case as shown below entering 2 results in the Table Item named John
Try some additional test cases yourself to become more familiar with these keys.
Did You Know?
DynamoDB was originally developed by Amazon to meet the demands of their e-commerce platform during the holiday shopping season. The system needed to handle the sudden spike in traffic and maintain low latency for a large number of concurrent users. DynamoDB's design principles and scalability were tested and proven in this high-stakes environment, ensuring its reliability and performance even under extreme load conditions.
Congratulations
You have completed the lab journey. In this lab:
You have successfully created an Amazon DynamoDB table.
You have inserted multiple items into the table using a partition key and sort key.
You have successfully searched for items in the table using the partition and sort keys.