Create Table (sample:mails)

aws dynamodb create-table --table-name mails \
--attribute-definitions \
    AttributeName=id,AttributeType=S \
    AttributeName=Name,AttributeType=S \
--key-schema \
    AttributeName=id,KeyType=HASH \
    AttributeName=Name,KeyType=RANGE \
--provisioned-throughput \
    ReadCapacityUnits=2,WriteCapacityUnits=2

put-item

aws dynamodb put-item \
    --table-name mails \
    --item '{"id": {"S": "testid1"},"Name": {"S": "Alice"},"mail": {"S": "alice@test.mail"} }' \
    --return-consumed-capacity TOTAL

{
    "ConsumedCapacity": {
        "CapacityUnits": 1.0,
        "TableName": "mails"
    }
}

項目を書き込む

Scan

aws dynamodb scan --table-name mails

{
    "Count": 2,
    "Items": [
        {
            "mail": {
                "S": "test@test.com"
            },
            "id": {
                "S": "1"
            },
            "Name": {
                "S": "test"
            }
        },
        {
            "mail": {
                "S": "alice@test.mail"
            },
            "id": {
                "S": "testid1"
            },
            "Name": {
                "S": "Alice"
            }
        }
    ],
    "ScannedCount": 2,
    "ConsumedCapacity": null
}

get-item(Key Select)

aws dynamodb get-item --table-name mails --key '{ "id": {"S": "1" },"Name": {"S": "test"} }'

{
    "Item": {
        "mail": {
            "S": "test@test.com"
        }, 
        "id": {
            "S": "1"
        }, 
        "Name": {
            "S": "test"
        }
    }
}

Record Count

aws dynamodb scan --table-name mails --select "COUNT"

{
    "Count": 2, 
    "ScannedCount": 2, 
    "ConsumedCapacity": null
}

list-tables

aws dynamodb list-tables
{
    "TableNames": [
        "mails"
    ]
}

delete-item(Key Select)

aws dynamodb delete-item --table-name mails --key '{ "id": {"S": "1" },"Name": {"S": "test"} }'
aws dynamodb scan --table-name mails --select "COUNT"
{
    "Count": 1, 
    "ScannedCount": 1, 
    "ConsumedCapacity": null
}

delete-table

aws dynamodb delete-table --table-name mails
{
    "TableDescription": {
        "TableArn": "arn:aws:dynamodb:ap-northeast-1:699559627754:table/mails", 
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0, 
            "WriteCapacityUnits": 2, 
            "ReadCapacityUnits": 2
        }, 
        "TableSizeBytes": 0, 
        "TableName": "mails", 
        "TableStatus": "DELETING", 
        "TableId": "4603179a-b965-4d40-b350-55954959646e", 
        "ItemCount": 0
    }
}