DEV Community

Revathi Joshi for AWS Community Builders

Posted on • Updated on

DynamoDB and its Control Pane Operations - 1

In the 1st part of this blog, I am going to show you some of the Control Pane Operations of the DynamoDB, such as

CreateTable - Creates a new table
DescribeTable – Returns information about a table, such as its primary key schema, throughput settings, and index information.
ListTable – Returns the names of all of your tables in a list.

The remaining 2 Control Pane Operations will be covered in the next blog - DynamoDB and its Control Pane Operations - 2.

UpdateTable – Modifies the settings of a table.
DeleteTable – Removes a table and all of its dependent objects from DynamoDB.

DynamoDB is a key-value, non-relational database that uses a simple key-value method to store data. A key-value database stores data as a collection of key-value pairs in which a key serves as a unique identifier, which is called the Primary Key. Also known as Partition Key / Hash Key.

DynamoDB uses the partition key’s value as an input to an internal hash function. The output from the hash function determines the partition in which the item is stored. Each item’s location is determined by the hash value of its partition key.

The Primary Key name and type must be specified on table creation. In this article, I am going to create

1. 1st table "Famous-Movies" with a Primary Key which consists of a single attribute, such as “Title” as an identifier.

2. 2nd table "Movies" with Primary key / Partition key and Sort key: Referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key - "Title", and the second attribute is the sort key - "Review". All data under a partition key is sorted by the sort key value.

Terminology

The following are the DynamoDB's core concepts:

Table

A collection of DynamoDB items. For example, in our application, the table "Famous-Movies" contain the data for Title, Review, Actor, PostedBy and Songs.

Item

An item is a group of attributes that is uniquely identifiable. It is comparable to a row in a relational database.

Attribute

A single data element on an item. It is comparable to a fields or columns in a relational database. However, unlike columns in a relational database, attributes do not need to be specified at table creation, other than the primary key discussed later in this module. Attributes can be simple types such as strings, integers, or Boolean, or they can be complex types such as lists or maps.

Data types

The only data types allowed for primary key attributes are string, number, or binary.

Read/Write Capacity Modes

Provisioned mode Is default and free-tier eligible. It controls how you are charged for read and write throughput

per second

and how you manage capacity. Specify throughput capacity in terms of read capacity units (RCUs) and write capacity units (WCUs).

Please visit my GitHub Repository for DynamoDB articles on various topics being updated on constant basis.

Let's get started!

Pre-requisites:

  • AWS user account with admin access, not a root account.
  • Cloud9 IDE
  • AWS Command Line Interface (AWS CLI) enables you to interact with AWS services using commands in your command-line shell.

Objectives

In this tutorial, you create 2 DynamoDB tables with the AWS CLI using the AWS Cloud9 Management Console and use the tables to describe and list the tables by using the AWS CLI.

  • Create 1st DynamoDB Table with Primary Key/Partition Key. Create 2nd DynamoDB Table with Primary Key and a Sort Key.
  • Explain the Required Parameters for Create Table.
  • Describe Table
  • List Table
  • Cleanup

Steps of Implementing the Objectives

1. Create-table - Copy the commands below along with the wait commands and paste them in your AWS Cloud9 command prompt. Each command waits for the tables to finish creating.

1st Table "Famous-Movies" with a Primary Key


aws dynamodb create-table \
    --table-name Famous-Movies \
    --attribute-definitions \
        AttributeName=Title,AttributeType=S \
    --key-schema \
        AttributeName=Title,KeyType=HASH \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5
aws dynamodb wait table-exists --table-name Famous-Movies
Enter fullscreen mode Exit fullscreen mode

Using create-table for "Famous-Movies" table, returns the following sample result.

Image description

Image description

2nd Table "Movies" with a Primary Key and a Sort Key


aws dynamodb create-table \
    --table-name Movies \
    --attribute-definitions \
        AttributeName=Title,AttributeType=S \
        AttributeName=Review,AttributeType=S \
    --key-schema \
        AttributeName=Title,KeyType=HASH \
        AttributeName=Review,KeyType=RANGE \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5
aws dynamodb wait table-exists --table-name Movies
Enter fullscreen mode Exit fullscreen mode

Using create-table for "Movies" table, returns the following sample result.

Image description

Image description

2. Explain the Required Parameters for Create Table.

create-table - When you use the create-table operation, it will create a new table in your account, and the region. If you want to create the table with the same name, then you have to create in a different region.
CreateTable is an asynchronous operation. Upon receiving a CreateTable request, DynamoDB immediately returns a response with a TableStatus of "CREATING". After the table is created, DynamoDB sets the TableStatus to "ACTIVE". You can perform read and write operations only on an ACTIVE table.

table-name (string) - The name of the table to create

attribute-definitions (list) - An array of attributes that describe the key schema for the table and indexes.
AttributeName -> (string)
AttributeType -> (string)

key-schema (list) - Specifies the attributes that make up the primary key for a table or an index. The attributes in KeySchema must also be defined in the AttributeDefinitions array.
Each KeySchemaElement in the array is composed of
AttributeName - The name of this key attribute.
KeyType - The role that the key attribute will assume:
HASH - partition key
RANGE - sort key
For a simple primary key (partition key), you must provide exactly one element with a KeyType of HASH.
For a composite primary key (partition key and sort key), you must provide exactly two elements, in this order: The first element must have a KeyType of HASH, and the second element must have a KeyType of RANGE.

provisioned-throughput
ReadCapacityUnits=10,WriteCapacityUnits=5

Represents the provisioned throughput settings for a specified table or index. The settings can be modified using the UpdateTable operation.
Operations in DynamoDB consume capacity from the table. When the table is using Provisioned Capacity, read operations will consume Read Capacity Units (RCUs) and write operations will consume Write Capacity Units (WCUs). For more information please see the Read/Write Capacity Mode in the DynamoDB Developer Guide.
ReadCapacityUnits
The maximum number of strongly consistent reads consumed per second before DynamoDB returns a ThrottlingException.
WriteCapacityUnits
The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException.

aws dynamodb wait table-exists --table-name xxxxxxx
Run the following AWS CLI command to wait until the table becomes ACTIVE.

3. Describe Table
To verify that DynamoDB has finished creating the tables, use the describe-table command.

aws dynamodb describe-table --table-name Famous-Movies | grep TableStatus
Enter fullscreen mode Exit fullscreen mode

Image description

aws dynamodb describe-table --table-name Movies | grep TableStatus
Enter fullscreen mode Exit fullscreen mode

Image description

This command returns the following result. When DynamoDB finishes creating the table, the value of the TableStatus field is set to ACTIVE.

"TableStatus": "ACTIVE",

4. List Tables - lists all of the tables associated with the current AWS account and Region.

aws dynamodb list-tables
Enter fullscreen mode Exit fullscreen mode

Image description

5. Cleanup

Delete all the DynamoDB tables from AWS Management Console.

What we have done so far

Successfully created DynamoDB Tables, Described the parameters for the create-table operation and Listed the newly created DynamoDB tables.

Oldest comments (0)