Help us understand the problem. What is going on with this article?

DynamoDB CLI

実際にコンソールの画面を確認しながら、実施してみるのがよい。

create-table

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

put-item

aws dynamodb put-item \
--table-name Music  \
--item \
    '{"Artist": {"S": "Namie Amuro"}, "SongTitle": {"S": "cotrail"}, "AlbumTitle": {"S": "fell"}, "Awards": {"N": "1"}}'

aws dynamodb put-item \
    --table-name Music \
    --item \
    '{"Artist": {"S": "one ok rock"}, "SongTitle": {"S": "kannzenkankakudremer"}, "AlbumTitle": {"S": "Niche Syndrome"}, "Awards": {"N": "10"} }'

get-item

aws dynamodb get-item --consistent-read \
    --table-name Music \
    --key '{ "Artist": {"S": "Namie Amuro"}, "SongTitle": {"S": "cotrail"}}'

update-item

aws dynamodb update-item \
    --table-name Music \
    --key '{ "Artist": {"S": "one ok rock"}, "SongTitle": {"S": "kannzenkankakudremer"}}' \
    --update-expression "SET AlbumTitle = :newval" \
    --expression-attribute-values '{":newval":{"S":"Updated Album Title"}}' \
    --return-values ALL_NEW

query

aws dynamodb query \
    --table-name Music \
    --key-condition-expression "Artist = :name" \
    --expression-attribute-values  '{":name":{"S":"one ok rock"}}'

GSI

aws dynamodb update-table \
    --table-name Music \
    --attribute-definitions AttributeName=AlbumTitle,AttributeType=S \
    --global-secondary-index-updates \
    "[{\"Create\":{\"IndexName\": \"AlbumTitle-index\",\"KeySchema\":[{\"AttributeName\":\"AlbumTitle\",\"KeyType\":\"HASH\"}], \
    \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 10, \"WriteCapacityUnits\": 5      },\"Projection\":{\"ProjectionType\":\"ALL\"}}}]" 


aws dynamodb query \
    --table-name Music \
    --index-name AlbumTitle-index \
    --key-condition-expression "AlbumTitle = :name" \
    --expression-attribute-values  '{":name":{"S":"Niche Syndrome"}}'

delete-table

aws dynamodb delete-table --table-name Music

LSI

aws dynamodb create-table   --table-name Music \
--attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S \
                        AttributeName=AlbumTitle,AttributeType=S  \
--key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \
--provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5 \
--local-secondary-indexes     \
    "[{\"IndexName\": \"AlbumTitleIndex\",
       \"KeySchema\":[{\"AttributeName\":\"Artist\",\"KeyType\":\"HASH\"},
                      {\"AttributeName\":\"AlbumTitle\",\"KeyType\":\"RANGE\"}],
       \"Projection\":{\"ProjectionType\":\"INCLUDE\",  \"NonKeyAttributes\":[\"Genre\", \"Year\"]}}]" 
セカンダリインデックス 説明
GSI テーブルに対し、パーティションキー+レンジキーだと効率の悪くなるクエリ(キー以外を条件にした検索等)を効率良くするために作成する明示的インデックス。全く別の属性をパーティションキー+レンジキーとして指定できる。
LSI グローバル同様明示的に追加するインデックスだが、パーティションキーは変更できない。

Amazon DynamoDB

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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした