LoginSignup
1
0

More than 1 year has passed since last update.

DynamoDBのローカル開発環境構築(マイグレーション編)

Posted at

概要

前回の記事でローカル開発環境にDynamoDBのインストール方法を記載しました。
今回はTBL作成やデータのロードに関する記事となります。

TBL確認

TBL一覧の確認
~/develop/aws/dynamodb/dynamodb_local_latest $ aws dynamodb list-tables --endpoint-url http://localhost:8000                         
{
    "TableNames": []
}

TBL作成

Musicテーブル作成
aws dynamodb create-table \
    --table-name Music \
    --attribute-definitions \
        AttributeName=Artist,AttributeType=S \
        AttributeName=SongTitle,AttributeType=S \
    --key-schema \
        AttributeName=Artist,KeyType=HASH \
        AttributeName=SongTitle,KeyType=RANGE \
    --provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5 \
    --endpoint-url http://localhost:8000
MusicTBLへのデータ挿入
aws dynamodb put-item \
    --table-name Music  \
    --item \
        '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"}, "Awards": {"N": "1"}}' \
--endpoint-url http://localhost:8000
MusicTBLへのデータ取得
aws dynamodb get-item --consistent-read \
    --table-name Music \
    --key '{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}}' \
    --endpoint-url http://localhost:8000
MusicTBLへのデータ更新
aws dynamodb update-item \
    --table-name Music \
    --key '{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}}' \
    --update-expression "SET AlbumTitle = :newval" \
    --expression-attribute-values '{":newval":{"S":"Updated Album Title"}}' \
    --return-values ALL_NEW \
    --endpoint-url http://localhost:8000
MusicTBLへのクエリ実行
aws dynamodb query \
    --table-name Music \
    --key-condition-expression "Artist = :name" \
    --expression-attribute-values  '{":name":{"S":"Acme Band"}}' \
    --endpoint-url http://localhost:8000
1
0
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
1
0