66
Help us understand the problem. What are the problem?

posted at

updated at

aws cli で DynamoDB を使う

city という名前のテーブルを作成

aws dynamodb create-table --table-name 'cities' \
--attribute-definitions '[{"AttributeName":"key","AttributeType": "S"}]' \
--key-schema '[{"AttributeName":"key","KeyType": "HASH"}]' \
--provisioned-throughput '{"ReadCapacityUnits": 5,"WriteCapacityUnits": 5}'

データの挿入

#
aws dynamodb put-item --table-name cities --item '{ "population": { "N": "38164" }, "date_mod": { "S": "1950-6-22" }, "key": { "S": "t0924" }, "name": { "S": "足利" } }'
#
aws dynamodb put-item --table-name cities --item '{ "population": { "N": "72391" }, "date_mod": { "S": "1950-8-30" }, "key": { "S": "t0925" }, "name": { "S": "日光" } }'
#
aws dynamodb put-item --table-name cities --item '{ "population": { "N": "56148" }, "date_mod": { "S": "1950-9-7" }, "key": { "S": "t0926" }, "name": { "S": "下野" } }'
#

データのスキャン

aws dynamodb scan --table-name cities

キーを指定してデータの取得

aws dynamodb get-item --table-name cities  --key '{ "key": {"S": "t0926" }  }'

キーを指定してデータの削除

aws dynamodb delete-item --table-name cities  --key '{"key": {"S": "t0924"}}'

テーブルの削除

aws dynamodb delete-table --table-name cities

レコード数のカウント

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

テーブル名の取得

aws dynamodb list-tables

テーブルに関する情報の取得

aws dynamodb describe-table --table-name cities

ローカルに立てた DynamoDB を取り扱う時

1) テーブル名の取得

aws dynamodb list-tables --endpoint-url http://localhost:8000

2) データのスキャン

aws dynamodb scan --table-name cities --endpoint-url http://localhost:8000

次のバージョンで確認しました。

$ aws --version
aws-cli/1.19.1 Python/3.9.5 Linux/5.11.0-34-generic botocore/1.20.0
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
66
Help us understand the problem. What are the problem?