LoginSignup
2
2

More than 5 years have passed since last update.

DynamoDBのサンプルをcliで作成する

Last updated at Posted at 2017-07-20

About

AWSのドキュメント にDynamoDBのテーブルを作成するものがあるが、マネジメントコンソールから作る例しか見当たらなかったので、cliから作る例を貼っておく。すでにあったら消すかも

実行方法

$ aws dynamodb create-table --cli-input-json file://product_catalog.json

のようにjsonを指定する

ProductCatalog

{
    "AttributeDefinitions": [
        {
            "AttributeName": "Id",
            "AttributeType": "N"
        }
    ],
    "TableName": "ProductCatalog",
    "KeySchema": [
        {
            "AttributeName": "Id",
            "KeyType": "HASH"
        }
    ],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
    }
}

Forum

{
    "AttributeDefinitions": [
        {
            "AttributeName": "Name",
            "AttributeType": "S"
        }
    ],
    "TableName": "Forum",
    "KeySchema": [
        {
            "AttributeName": "Name",
            "KeyType": "HASH"
        }
    ],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
    }
}

Thread

{
    "AttributeDefinitions": [
        {
            "AttributeName": "ForumName",
            "AttributeType": "S"
        },
        {
            "AttributeName": "Subject",
            "AttributeType": "S"
        }
    ],
    "TableName": "Thread",
    "KeySchema": [
        {
            "AttributeName": "ForumName",
            "KeyType": "HASH"
        },
        {
            "AttributeName": "Subject",
            "KeyType": "RANGE"
        }
    ],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
    }
}

Reply

{
    "AttributeDefinitions": [
        {
            "AttributeName": "Id",
            "AttributeType": "S"
        },
        {
            "AttributeName": "ReplyDateTime",
            "AttributeType": "S"
        },
        {
          "AttributeName": "PostedBy",
          "AttributeType": "S"
        },
        {
          "AttributeName": "Message",
          "AttributeType": "S"
        }
    ],
    "TableName": "Reply",
    "KeySchema": [
        {
            "AttributeName": "Id",
            "KeyType": "HASH"
        },
        {
            "AttributeName": "ReplyDateTime",
            "KeyType": "RANGE"
        }
    ],
    "GlobalSecondaryIndexes": [
        {
            "IndexName": "PostedBy-Message-Index",
            "KeySchema": [
                {
                    "AttributeName": "PostedBy",
                    "KeyType": "HASH"
                },
                {
                    "AttributeName": "Message",
                    "KeyType": "RANGE"
                }
            ],
            "Projection": {
                "ProjectionType": "ALL"
            },
            "ProvisionedThroughput": {
                "ReadCapacityUnits": 1,
                "WriteCapacityUnits": 1
            }
        }
    ],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
    }
}

2
2
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
2
2