LoginSignup
2
0

More than 5 years have passed since last update.

DynamoDB ローカルでチュートリアル

Posted at

DynamoDBをローカルで動かすことができたので、メモ。
あとはチュートリアルを試しながらって感じで。

1. ローカル実行用にDynamoDBをダウンロード

2.解凍し当該フォルダで実行

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

3.テーブルにアクセスしてみる

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

実行結果

{
    "TableNames": []
}

ブラウザでチュートリアル

下記URLにアクセスするとチュートリアルを試せる
http://localhost:8000/shell/

スクリーンショット 2017-12-30 9.15.07.png

右側のコンソール上で、 tutorial.start() と入力するとチュートリアルが開始される。

チュートリアルを進めていくと、最初にImageテーブルが作成される。
KeySchema が、primary key となり、ユニークなものとなる。

// This CreateTable request will create the Image table.
// With DynamoDB Local, tables are created right away. If you are calling
// a real DynamoDB endpoint, you will need to wait for the table to become
// ACTIVE before you can use it. See also dynamodb.waitFor().
var params = {
    TableName: 'Image',
    KeySchema: [
        {
            AttributeName: 'Id',
            KeyType: 'HASH'
        }
    ],
    AttributeDefinitions: [
        {
            AttributeName: 'Id',
            AttributeType: 'S'
        }
    ],
    ProvisionedThroughput:  {
        ReadCapacityUnits: 1,
        WriteCapacityUnits: 1
    }
};
console.log("Creating the Image table");
dynamodb.createTable(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

スクリーンショット 2017-12-30 9.25.31.png

ターミナルでもImageテーブルが作成されていることが確認できる。

terminal$ aws dynamodb list-tables --endpoint-url http://localhost:8000
{
"TableNames": [
"Image"
]
}

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