102
76

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

aws cli で DynamoDB を使う

Last updated at Posted at 2017-10-07

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

go_create.sh
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}'

データの挿入

go_insert.sh
TABLE='cities'
aws dynamodb put-item --table-name $TABLE --item '{ "population": { "N": "38164" }, "date_mod": { "S": "1950-6-22" }, "key": { "S": "t0924" }, "name": { "S": "足利" } }'
#
aws dynamodb put-item --table-name $TABLE --item '{ "population": { "N": "72391" }, "date_mod": { "S": "1950-8-30" }, "key": { "S": "t0925" }, "name": { "S": "日光" } }'
#
aws dynamodb put-item --table-name $TABLE --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

バックアップ

バックアップの作成

TABLE="cities"
aws dynamodb create-backup --table-name $TABLE \
	--backup-name $TABLE"-Backup"

バックアップの一覧

aws dynamodb list-backups

別テーブルにリストア

TARGET="cities2"
#
aws dynamodb restore-table-from-backup \
	--target-table-name $TARGET \
--backup-arn arn:aws:dynamodb:ap-northeast-1:372407516321:table/cities/backup/01658017317622-d319e000

バックアップの削除

aws dynamodb delete-backup \
--backup-arn arn:aws:dynamodb:ap-northeast-1:372407516321:table/cities/backup/01658017317622-d319e000

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

テーブル名の取得

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

データのスキャン

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

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

$ aws --version
aws-cli/2.7.12 Python/3.9.11 Linux/5.15.0-25-generic exe/x86_64.ubuntu.22 prompt/off
102
76
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
102
76

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?