公式ドキュメント

前提

参考

事前準備

  • 作業用ディレクトリ作成
    1
    
    $ mkdir -p ~/dynamodbwork/json; cd ./dynamodbwork

テーブル操作

テーブルのリストを表示する

1
2
3
4
5
$ aws dynamodb \
list-tables \
--endpoint-url http://localhost:8000 > ./json/list-tables.json

$ more ./json/list-tables.json

出力結果のjsonファイル

1
2
3
{
    "TableNames": []
}

テーブル作成

定義用jsonファイル

1
$ more ./json/testTableDefinition.json
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
    "TableName": "testTable",
    "AttributeDefinitions": [
        {
            "AttributeName": "hash_key_attribute_name",
            "AttributeType": "S"
        },
        {
            "AttributeName": "range_key_attribute_name",
            "AttributeType": "S"
        }
    ],
    "KeySchema": [
        {
            "KeyType": "HASH",
            "AttributeName": "hash_key_attribute_name"
        },
        {
            "KeyType": "RANGE",
            "AttributeName": "range_key_attribute_name"
        }
    ],
    "ProvisionedThroughput": {
        "WriteCapacityUnits": 5,
        "ReadCapacityUnits": 5
    }
}

1
2
3
4
$ aws dynamodb \
create-table \
--endpoint-url http://localhost:8000 \
--cli-input-json file://json/testTableDefinition.json

テーブルの内容を表示する

1
2
3
4
5
6
$ aws dynamodb \
describe-table \
--endpoint-url http://localhost:8000 \
--table-name testTable > ./json/testTable.json

$ more ./json/testTable.json

テーブル定義の更新

更新用jsonファイル

1
$ more ./json/testTableUpdate.json
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
    "TableName": "testTable",
    "AttributeDefinitions": [
        {
            "AttributeName": "hash_key_attribute_name",
            "AttributeType": "S"
        },
        {
            "AttributeName": "range_key_attribute_name",
            "AttributeType": "S"
        }
    ],
    "ProvisionedThroughput": {
        "WriteCapacityUnits": 10,
        "ReadCapacityUnits": 10
    }
}

1
2
3
4
$ aws dynamodb \
update-table \
--endpoint-url http://localhost:8000 \
--cli-input-json file://json/testTableUpdate.json

更新後のテーブルの内容を表示する

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ aws dynamodb \
describe-table \
--endpoint-url http://localhost:8000 \
--table-name testTable > ./json/testTableUdated.json

$ diff ./json/testTable.json ./json/testTableUdated.json
16c16
<             "WriteCapacityUnits": 5,
---
>             "WriteCapacityUnits": 10,
18c18
<             "ReadCapacityUnits": 5,
---
>             "ReadCapacityUnits": 10,

テーブル削除

1
2
3
4
$ aws dynamodb \
delete-table \
--endpoint-url http://localhost:8000 \
--table-name testTable