How to create a DynamoDB Table in AWS
Amazon DynamoDB is a key-value and document database. It's a fully managed, multi-region, multi-master, durable database and can handle more than 10 trillion requests per day. It has built-in security, backup and restore, and in-memory caching for internet-scale applications. We can build applications with virtually unlimited throughput and storage.
For use cases that require even faster access with microsecond latency, DynamoDB Accelerator provides a fully managed in-memory cache. It is serverless with no servers to provision, patch, or manage and no software to install, maintain, or operate. It provides both provisioned and on-demand capacity modes. It encrypts all data by default.
We can use DynamoDB to build powerful web applications that automatically scale up and down, build interactive mobile and web apps with real-time updates.
Before we create a DynamoDB Table, let's understand its basic components.
A table is a collection of data. Similar to other databases, DynamoDB stores data in tables.
An item is a group of attributes that is uniquely identifiable among all of the other items. Each table contains zero or more items.
An attribute is a fundamental data element, something that does not need to be broken down any further. Each item is composed of one or more attributes.
- Partition key:
A simple primary key, composed of one attribute known as the partition key.
- Partition key and sort key:
It is referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key.
- Sort Key:
The sort key of an item is also known as its range attribute.
- DynamoDB Streams:
It is an optional feature that captures data modification events in DynamoDB tables.
DynamoDB has two billing models
- On-demand capacity mode:
In this mode we are charged for the data reads and writes our application performs on our tables. We do not need to specify how much read and write throughput we expect.
- Provisioned capacity mode:
Here we specify the number of reads and writes per second that we expect our application to require.
To know about DynamoDB and its pricing, click here.
In this article, we will create a simple DynamoDB Table with On-Demand mode and create a few items and perform a search on it.
- AWS Account (Create if you don’t have one).
What will we do?
- Login to AWS.
- Create a DynamoDB Table.
- Add items to the table and search for a record.
- Delete the Table
Login to AWS
Click here to go to AWS Login Page.
When we hit the above link, we will see a web page as follows where we are required to login using our login details.
Once we login into AWS successfully, we will see the main console with all the services listed as follows.
Create a DynamoDB Table
To create a DynamoDB Table, click on Services at the top left of the screen and search for DynamoDB.
You will see the homepage of Amazon DynamoDB. To create a table click on" Create table"
In the Table Name box type in the table name and specify the Partition key in the box. Untick the "Use default settings" check box.
Select the "On-Demand" option. Scroll down and click on the create table button. Your table will be created.
Add items in the Table and search for a record
To add data to your table, select the table we just created.
Select the Items tab. On the Items tab, choose to Create item.
In the data entry window, type the name that you want to add to the table as an item. Repeat the same step to add multiple entries or items.
To search for a particular item, in the filter add "Name" and specify the name that you want to search.
Change the other value, you will find the data you are looking for if it matches the query.
Delete the Table
You can easily delete a table from the DynamoDB console if you no longer need it. It is always a good idea to delete the resources if they are not needed.
To delete the table, select the table we just created and click on the "Delete Table"button.
In the confirmation dialog box, type Delete.
In this article, we learned to create our first DynamoDB table, add items to the table, and then queried the table to find the item we want. We also learned how to manage our DynamoDB tables and items through the AWS Management Console and delete it.