dynamo-db
  1. dynamo-db

DynamoDB Tutorial

DynamoDB is a NoSQL database service offered by Amazon Web Services (AWS). It is a fully managed, highly available, and scalable database that can handle large amounts of data. In this tutorial, we will explore the basics of DynamoDB.

Syntax

The syntax for creating a table in DynamoDB is as follows:

aws dynamodb create-table \
    --table-name TableName \
    --attribute-definitions AttributeName=AttributeType \
    --key-schema AttributeName=KeyType \
    --provisioned-throughput ReadCapacityUnits=RCU,WriteCapacityUnits=WCU \
    --region Region

Example

Let's create a table named "users" with userId as the primary key and username, email as attributes.

aws dynamodb create-table \
    --table-name users \
    --attribute-definitions AttributeName=userId,AttributeType=N AttributeName=username,AttributeType=S AttributeName=email,AttributeType=S \
    --key-schema AttributeName=userId,KeyType=HASH \
    --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
    --region us-west-2

Output

The output of the above command should be similar to the following:

{
    "TableDescription": {
        "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/users",
        "AttributeDefinitions": [
            {
                "AttributeName": "userId",
                "AttributeType": "N"
            },
            {
                "AttributeName": "username",
                "AttributeType": "S"
            },
            {
                "AttributeName": "email",
                "AttributeType": "S"
            }
        ],
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0,
            "WriteCapacityUnits": 5,
            "ReadCapacityUnits": 5
        },
        "TableSizeBytes": 0,
        "TableName": "users",
        "TableStatus": "CREATING",
        "KeySchema": [
            {
                "KeyType": "HASH",
                "AttributeName": "userId"
            }
        ],
        "CreationDateTime": 1640375825.6747355
    }
}

Explanation

In the above example, we used the AWS CLI to create a table named "users". The table has three attributes: userId, username, and email. The userId attribute is the primary key with the Hash Key type. We also defined the provisioned throughput to be 5 read capacity units and 5 write capacity units. Finally, we passed the region as "us-west-2" where the table will be created.

Use

DynamoDB can be used to store and retrieve large amounts of data in a highly reliable and scalable manner. It can be used in a variety of use cases, including web and mobile applications, gaming, IoT, and more.

Important Points

  • DynamoDB is a NoSQL database service offered by AWS.
  • It is fully managed and highly available.
  • DynamoDB can handle large amounts of data and is highly scalable.
  • The syntax for creating a table in DynamoDB is straightforward.
  • The primary key is required for every item in a table.
  • Provisioned throughput can be adjusted to handle varying workloads.

Summary

In this tutorial, we have learned the basics of DynamoDB. We explored the syntax and example of creating a table in DynamoDB, as well as its output and explanation. We also discussed the uses of DynamoDB and its important points. DynamoDB is a great option for organizations looking for a scalable and highly available database.

Published on: