CRUD DynamoDB from console and awscli

In this post, I am goint to use DynamoDB from the aws console and awscli.

The operations are: create table, CRUD (insert, select, update, delete), and drop table for both tools.


what is DynamoDB?

"Amazon DynamoDB is a key-value and document database" https://aws.amazon.com/dynamodb/


console

# navigate

aws console > Services > Database > DynamoDB > create table


# create

  • table name: student
  • primary key: id (string)

> create


# insert

  1. item tab > create item > item > add item > id=001 > save
  2. item tab > create item > item > add item > id=002, grade=B > save


# select

item tab > add filter > grade=B > search


# update

item tab > select "001" > append grade=B > save


# delete

item tab > tick "001" checkbox > actions > delete > delete


# drop

delete table (on upper left) > delete


awscli

# help

% aws dynamodb help


# create

% aws dynamodb create-table --table-name student \

   --attribute-definitions AttributeName=id,AttributeType=S \

   --key-schema AttributeName=id,KeyType=HASH \

   --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

% aws dynamodb list-tables                        

{
    "TableNames": [
        "student"
    ]
}


# insert

% aws dynamodb put-item --table-name student --item '{"id": {"S": "001"}}'
% aws dynamodb put-item --table-name student --item '{"id": {"S": "002"}, "grade": {"S": "B"}}'

% aws dynamodb scan --table-name student

{
    "Items": [
        {
            "id": {
                "S": "001"
            }
        },
        {
            "id": {
                "S": "002"
            },
            "grade": {
                "S": "B"
            }
        }
    ],
    "Count": 2,
    "ScannedCount": 2,
    "ConsumedCapacity": null
}


# select

% aws dynamodb scan --table-name student --scan-filter '{"grade": {"AttributeValueList":[ {"S":"B"} ], "ComparisonOperator": "EQ"}}'

{
    "Items": [
        {
            "id": {
                "S": "002"
            },
            "grade": {
                "S": "B"
            }
        }
    ],
    "Count": 1,
    "ScannedCount": 2,
    "ConsumedCapacity": null
}


# update

% aws dynamodb put-item --table-name student --item '{"id": {"S": "001"}, "grade": {"S": "A"}}'

% aws dynamodb scan --table-name student

{
    "Items": [
        {
            "id": {
                "S": "001"
            },
            "grade": {
                "S": "A"
            }
        },
        {
            "id": {
                "S": "002"
            },
            "grade": {
                "S": "B"
            }
        }
    ],
    "Count": 2,
    "ScannedCount": 2,
    "ConsumedCapacity": null
}


# delete

% aws dynamodb delete-item --table-name student --key '{"id": {"S": "001"}}'

% aws dynamodb scan --table-name student

{
    "Items": [
        {
            "id": {
                "S": "002"
            },
            "grade": {
                "S": "B"
            }
        }
    ],
    "Count": 1,
    "ScannedCount": 1,
    "ConsumedCapacity": null
}


# drop

% aws dynamodb delete-table --table-name student

% aws dynamodb list-tables

{
    "TableNames": []
}


Comments

Popular posts from this blog

Selenide: Quick Start

Minikube Installation for M1 Mac

Testinfra: Quick Start - Run Sample Test to EC2 server