• Articles
  • Tutorials
  • Interview Questions

AWS DynamoDB Tutorial for Beginners

AWS DynamoDB Tutorial for Beginners

What is AWS DynamoDB?

AWS DynamoDB is a fully managed NoSQL database. In it, no Database administration is required. It automatically spreads the data and traffic for tables over a sufficient number of servers to handle throughput and storage requirements. JSON formatted documents can be stored as items in AWS DynamoDB.

Check out this AWS Course video to learn more about AWS concepts.

Video Thumbnail

AWS DynamoDB tables are non-relational and are schema-free. There are tables in Amazon DynamoDB and each table has several items (rows) and each item has Keys and Attributes (Columns).

Core Concepts of AWS DynamoDB

  • Tables
    • In Amazon DynamoDB, the collection of items is known as a table. A table in AWS DynamoDB is not a structured table with a fixed number of cells or columns.
  • Items
    • Each table in Amazon DynamoDB contains one or more items. Items are made up of a group of attributes that are uniquely identifiable.
  • Attributes
    • Attributes in AWS DynamoDB are fundamental data elements or values that reside in an item. Equivalent to data values that reside in a particular cell of a table in a relational database.

In the next section of this AWS DynamoDB tutorial, we will learn about Accessing Amazon DynamoDB.

Accessing Amazon DynamoDB

Accessing DynamoDB is easy and can be done by any of the following three methods:

Common Line Interface (CLI): This method is very simple, you can open your command prompt and type the relevant commands and access the table. With the help of CLI, you can control multiple AWS services from the command line. It also helps you automate the scripts.

AWS Management Console: AWS Management Console displays an introductory screen that promptly directs you to create a table. Further, you can perform operations, such as creation, updating, and deletion of tables, through the console. It allows you to perform a wide range of operations including monitoring recent alerts, service health, and the latest DynamoDB news on the DynamoDB dashboard. 

Get 100% Hike!

Master Most in Demand Skills Now!

API: While AWS Console and CLI are used to interactively work with Amazon DynamoDB, to get the most out of DynamoDB, you can write application code by using AWS SDKs. AWS SDK offers a wide range of support services in DynamoDB in Java, JavaScript in the browser, .NET, Node.js, Ruby, C++, iOS, etc.

AWS DynamoDB API

DynamoDB offers a wide range of powerful API tools for table manipulation, data reads, and data modification. The following are the APIs operations that you need to use to work with Amazon DynamoDB:

  • Control plane
  • Data plane
  • DynamoDB streams

Let us discuss each one of them one by one:

  1. Control plane: Control plane allows you to create and manage DynamoDB tables. It is also used to work with streams, indexes, and other objects that are dependent on tables.

    You can perform the following operations in DynamoDB with the help of a control plane:

    CreateTable: It allows you to create tables. With the help of this, you can create one or more secondary indexes and enable DynamoBD Streams for the table.

    DeleteTable: It removes a table and all of its dependent objects from DynamoDB.

    DescribeTable: It returns information about a table including primary key schema, throughput settings, and index information.

    UpdateTable: It modifies the settings of a table or its indexes, creates or removes new indexes on a table, or modifies DynamoDB streams settings.

    ListTables: It returns the names of all tables that are present in the list.
  2. Data plane: Data plane operations allow you to create, read, and update data in tables. You can use PartiQL (SQL-Compatible Query Language for Amazon DynamoDB) to perform CRUD operations. You can also use DynamoDB classic CRUD APIs that separate each operation into a distinct API call.

    i) Creating Data
    PutItem: It writes a single item in a table. In this, you only have to specify the primary key attributes but not other attributes.
    BatchWriteItem: This is more efficient than calling PutItem multiple times because BatchWriteItem allows you to put 25 items in the table at once. Similarly, it can be used for deleting multiple items from one or more tables.

    ii) Reading Data
    GetItem: It retrieves a single item from a table or just a subset of its attributes. It also specifies the primary key for the item that you want.
    BatchGetItem: This is more efficient than calling GetItem multiple times as BatchGetItem retrieves up to 100 items from one or more tables.
    Query: It retrieves all items having a specific partition key. You can retrieve entire items or just a subset of their attributes.
    Scan: With the help of this, you can retrieve all items in the specified table or index. In addition to this, you can apply a filtering condition to return only the values that you need.

    iii) Updating Data
    UpdateItem: It modifies one or more attributes in an item with the help of a specific attribute in the item. You can also add new attributes and modify or remove existing attributes.

    iv) Deleting Data
    DeleteItem: This deletes a single item from a table with the help of a specific primary key.
    BatchWriteItem: It deletes up to 25 items from one or more tables. This is more efficient than DeletItem because you can collectively delete a large chunk of items from the table.
  3. DynamoDB Streams: With the help of DynamoDB Streams, you can enable or disable a stream on a table and allow access to data modification records contained in a stream.

    It has the following types of streams:
    ListStreams: It returns a list of all your streams or just the stream for a specific table.
    DescribeStream: It returns information about a stream such as its Amazon Resource Name (ARN) and where your application can begin reading the first few stream records.
    GetShardIterator: It returns a shared iterator, a data structure used to retrieve records from the stream.
    GetRecords: Retrieves one or more stream records by using a given shard iterator. 

In the next section of this AWS DynamoDB tutorial, we will learn about working use cases.

AWS DynamoDB Working Use Case

AWS DynamoDB Working Use Case

There are a lot of use cases with AWS DynamoDB but for your understanding, a simple microservice datastore use case is used.

As per the above illustration, consider a social media stream is incoming and a Lambda is triggered. To learn what is Lambda, check out this tutorial on Amazon Lambda. After the Lambda gets triggered the code for hashtag generation runs.

The hashtag data generated from the social media stream is stored in the AWS DynamoDB because it is a serverless store and provides consistent and fast performance. You can use the data stored in the Amazon DynamoDB to create a social media trend and analytics on it.

Amazon DynamoDB Features

There are 3 main AWS DynamoDB Features available that make it efficient to use from a business perspective.

AWS11
  • Performance at Scale
  • Serverless
  • Enterprise-ready

Performance at Scale

  • Real-time data processing
    • AWS DynamoDB stores its items in chronological time order. Whenever a change occurs in a particular item it can be captured and compared with other items
  • Microsecond latency
    • Even while receiving millions of requests per second, the time it takes to read will just be milliseconds to microseconds
  • Key-value and document-based
    • This flexible feature allows data to be in any structure the business needs. It could change according to the change in the storage structure of the business

Certification in Cloud and Devops

Serverless

  • Autoscaling
    • Whenever your website’s request for some data increases or decreases, the autoscaling feature will increase or decrease the size of the database in synchrony. This helps in maintaining costs for your database uses
  • Read/write modes
    • You can either set an on-demand mode or a provisioning mode.
    • In the on-demand mode, the autoscaling feature will take care of provisioning new databases.
    • In the provisioning mode, you have to set tables, permissions, and also increase and decrease capacity

Enterprise Ready

  • Encryption for data
    • Amazon DynamoDB encrypts customer data at REST which improves security. They provide security by creating encryption keys using the AWS Key Management Service.
  • Point-in-time recovery
    • This prevents accidental deletion or updation operations of your tables
    • There will be a continuous backup of your data up to a certain time period which you can use recover at any point in time.

In the next section of this Amazon DynamoDB tutorial, we will take a look at the pricing and costs.

AWS DynamoDB Pricing

Free tier eligible forever but the data content has to be lesser than 25 GB.

Amazon DynamoDB pricing

The pricing varies according to the region. Considering North Virginia as the default region, let us look at the price for each service under Amazon DynamoDB.

On-Demand capacity mode

Data Storage

  • First, 25 GB stored per month is free
  • $0.25 per GB-month thereafter

Read/Write Requests

  • Write request unit – $1.25 per million write request units
  • Read request units – $0.25 per million read request units

Backup and Restore

  • $0.20 per GB-month

Provisioned capacity mode

Data Storage

  • First 25 GB stored per month is free
  • $0.25 per GB-month thereafter

Read/Write Requests

  • Write capacity unit (WCU) – $0.00065 per WCU
  • Read capacity unit (RCU) – $0.00013 per RCU

Backup and Restore

  • $0.20 per GB-month

Let’s get started with AWS DynamoDB!

Become a Cloud and DevOps Architect

In the next section of this Amazon DynamoDB tutorial, we will take a look at some Case studies of AWS DynamoDB

Amazon DynamoDB: Case Studies

DynamoDB offers some of the best features such as built-in security, backup and restores, and in-memory caching. Considering its high reliability, many small, as well as large companies, use DynamoDB. 

Here are a few examples of some of the companies that benefit from using DynamoDB: 

Nexon: Nexon used Amazon DynamoDB as their primary database for their superhit game HIT. Amazon DynamoDB helped Nexon to deliver steady latency to provide an excellent mobile gaming experience.

MLB Advanced Media (MLBAM): Amazon DynamoDB helped MLBAM to scale up the support for games on a single day. The company also stated that DynamoDB helped them to power queries and support for fast data retrieval.

Expedia: With the help of Amazon DynamoDB, Expedia was able to collect data for test-and-learn experiments. DynamoDB made data monitoring very easy and also helped in smoothly scaling it further.

Hands-on: Creating an AWS DynamoDB table, inserting data to it, and querying it

First, Now in this AWS DynamoDB tutorial, let’s create an AWS DynamoDB table.

Step 1: Log on to the AWS Management Console and go to AWS DynamoDB Service. To start with creating an Amazon DynamoDB table, click on “create table”

Amazon Dynamodb

Step 2: First give a name for your table “Table name”, and then mention the primary key for your table “Primary key”.

create dynamodb table

Step 3: You can create as many tables as you like, and you can click on “Overview” to get all the information about the table.

click on Overview

We have now created a table called “Student”. Now let us insert some items in it.

Step 1: Click on “Items” and then choose “Create Item”.

choose Create Item

Step 2: Now click on the plus symbol and choose to “Append” with a specified data type (eg. String). You can add any data type.

choose to Append

Step 3: Now add Field names and Values for the appended spaces. It will look like this after entering the data. After that hit the “Save” button.

add Field names and Values

Step 4: This is what the console displays after entering multiple items. Creating a table and inserting contents is this simple. You don’t need to do all the work, AWS console is designed to manage it.

Creating a table and inserting contents

We have created and inserted values into an AWS DynamoDB table called ‘Student’ and mentioned ‘StdID’ as the primary key. Now let us do some simple querying.

Step 1: Click on the ‘Add filter’ button to start with querying. Now add filter attributes and values to make it more specific.

Click on the Add filter

Step 2: In this query example, we are taking the query as ‘Name = Keanu’, and all the items with the name “Keanu” are filtered and displayed.

add filter attributes and values

Step 3: In this query example, we give the filter as ‘Address Contains ba’. This will filter all the Address field values which have the sequence “ba” in them.

filter as Address Contains ba

Amazon DynamoDB is in the top 20 most used AWS services. As it is widely used, learning adds value to you. In this AWS DynamoDB tutorial, we have learned the concepts of AWS DynamoDB both theoretically and practically. Hope this helps you!

Course Schedule

Name Date Details
AWS Certification 14 Dec 2024(Sat-Sun) Weekend Batch View Details
21 Dec 2024(Sat-Sun) Weekend Batch
28 Dec 2024(Sat-Sun) Weekend Batch

About the Author

Senior Cloud Computing Associate

Rupinder is a distinguished Cloud Computing & DevOps associate with architect-level AWS, Azure, and GCP certifications. He has extensive experience in Cloud Architecture, Deployment and optimization, Cloud Security, and more. He advocates for knowledge sharing and in his free time trains and mentors working professionals who are interested in the Cloud & DevOps domain.