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.
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.
The following are the DynamoDB's core concepts:
A collection of DynamoDB items. For example, in our application, the table "Famous-Movies" contain the data for Title, Review, Actor, PostedBy and Songs.
An item is a group of attributes that is uniquely identifiable. It is comparable to a row in a relational database.
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.
The only data types allowed for primary key attributes are string, number, or binary.
Provisioned mode Is default and free-tier eligible. It controls how you are charged for read and write throughput
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.
- 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.
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
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 \
aws dynamodb wait table-exists --table-name Famous-Movies
Using create-table for "Famous-Movies" table, returns the following sample result.
2nd Table "Movies" with a Primary Key and a Sort Key
aws dynamodb create-table \
--table-name Movies \
aws dynamodb wait table-exists --table-name Movies
Using create-table for "Movies" table, returns the following sample result.
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.
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.
The maximum number of strongly consistent reads consumed per second before DynamoDB returns a ThrottlingException.
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
aws dynamodb describe-table --table-name Movies | grep TableStatus
This command returns the following result. When DynamoDB finishes creating the table, the value of the TableStatus field is set to ACTIVE.
4. List Tables - lists all of the tables associated with the current AWS account and Region.
aws dynamodb list-tables
Delete all the DynamoDB tables from AWS Management Console.
Successfully created DynamoDB Tables, Described the parameters for the create-table operation and Listed the newly created DynamoDB tables.