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.
In this context, we shall look into how to create a simple DynamoDB Table with On-Demand mode and create a few items and perform a search on it.
To know about DynamoDB and its pricing, click here.
Basic components of a DynamoDB Table includes:
- Tables: A table is a collection of data. Similar to other databases, DynamoDB stores data in tables.
- Items: An item is a group of attributes that is uniquely identifiable among all of the other items. Each table contains zero or more items.
- Attributes: 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.
Different billing models for DynamoDB includes:
- 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.
Steps to create a simple DynamoDB Table in AWS
1. Create AWS Account
Click here to create a free AWS account
2. Login to AWS
Now, go to the AWS Login page:
Once opened, you can login using the login details.
Once we login into AWS successfully, we will see the main console with all the services listed.
3. 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.
4. 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.
How to Delete the Amazon DynamoDB 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.