2017-04-27 10 views
1

Amazon DynamoDBのローカルバージョンをダウンロードしました。シェルを使用してテーブルを作成しようとしています。私はシェルからコードを実行すると、それは私にエラーを与える:ローカルDynamoDBでテーブルを作成できません

"message":"The security token included in the request is invalid." 
"code":"UnrecognizedClientException" 
"time":"2017-04-27T12:50:35.880Z" 
"statusCode":400 
"retryable":false 

は、コードを作成している:

var dynamodb = new AWS.DynamoDB(); 
var params = { 
    "AttributeDefinitions": [ 
     { 
      "AttributeName": "UserId", 
      "AttributeType": "N" 
     }, 
     { 
      "AttributeName": "FirstName", 
      "AttributeType": "S" 
     }, 
     { 
      "AttributeName": "LastName", 
      "AttributeType": "S" 
     }, 
     { 
      "AttributeName": "CellPhoneNumber", 
      "AttributeType": "N" 
     } 
    ], 
    "TableName": "Users", 
    "KeySchema": [ 
     { 
      "AttributeName": "UserId", 
      "KeyType": "HASH" 
     }, 
     { 
      "AttributeName": "CellPhoneNumber", 
      "KeyType": "RANGE" 
     } 
    ], 
    "LocalSecondaryIndexes": [ 
     { 
      "IndexName": "UserIndex", 
      "KeySchema": [ 
       { 
        "AttributeName": "UserId", 
        "KeyType": "HASH" 
       }, 
       { 
        "AttributeName": "CellPhoneNumber", 
        "KeyType": "RANGE" 
       } 
      ], 
      "Projection": { 
       "ProjectionType": "KEYS_ONLY" 
      } 
     } 
    ], 
    "ProvisionedThroughput": { 
     "ReadCapacityUnits": 5, 
     "WriteCapacityUnits": 5 
    } 
} 

dynamodb.createTable(params, function(err, data) { 
    if (err) ppJson(err); // an error occurred 
    else ppJson(data); // successful response 

}); 

私は地元DynamoDBの中にテーブルを作成するにはどうすればよいですか?まずDBを作成する必要がありますか?私はいつもSQLで作業していて、NoSQLを使用しているのは初めてです。

答えて

0

データベースを作成する必要はありません。テーブルを作成するだけです。

次の設定をローカルdynamodbに使用します。エンドポイントURLは重要です。その他の属性はダミー値です(つまり、任意の値)。

var creds = new AWS.Credentials('akid', 'secret', 'session'); 

AWS.config.update({ 
    region: "us-west-2", 
    endpoint: "http://localhost:8000", 
    credentials : creds 
}); 

また、テーブルの作成中にすべての属性を定義する必要はありません。主要属性のみを定義する必要があります。そうしないと、エラーが発生します。

私は(HTTPシェルで上記のコードを実行すると、テーブルを作成するために、全コード(http://localhost:8000/shell/):-

var dynamodb = new AWS.DynamoDB({ 
    region: 'us-east-1', 
    endpoint: "http://localhost:8000" 
}); 
var tableName = "Movies"; 

var params = { 
    "AttributeDefinitions": [ 
     { 
      "AttributeName": "UserId", 
      "AttributeType": "N" 
     }, 
     { 
      "AttributeName": "CellPhoneNumber", 
      "AttributeType": "N" 
     } 
    ], 
    "TableName": "PBUsers", 
    "KeySchema": [ 
     { 
      "AttributeName": "UserId", 
      "KeyType": "HASH" 
     }, 
     { 
      "AttributeName": "CellPhoneNumber", 
      "KeyType": "RANGE" 
     } 
    ], 
    "LocalSecondaryIndexes": [ 
     { 
      "IndexName": "UserIndex", 
      "KeySchema": [ 
       { 
        "AttributeName": "UserId", 
        "KeyType": "HASH" 
       }, 
       { 
        "AttributeName": "CellPhoneNumber", 
        "KeyType": "RANGE" 
       } 
      ], 
      "Projection": { 
       "ProjectionType": "KEYS_ONLY" 
      } 
     } 
    ], 
    "ProvisionedThroughput": { 
     "ReadCapacityUnits": 5, 
     "WriteCapacityUnits": 5 
    } 
} 

dynamodb.createTable(params, function(err, data) { 
    if (err) { 
     if (err.code === "ResourceInUseException" && err.message === "Cannot create preexisting table") { 
      console.log("message ====>" + err.message); 
     } else { 
      console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2)); 
     } 

    } else { 
     console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2)); 
    } 
}); 
+0

上で実行する必要があります:// localhostを:8000 /シェル/)、私はこのエラーを取得します: " ReferenceError:requireが定義されていません " – User2682

+0

スクリプトを更新しました。 – notionquest

関連する問題