该文档可能有点难以理解。由于您使用的是 dynamodb shell,我假设您要求使用 JavaScript 查询来创建表。
var params = {
TableName: 'student',
KeySchema: [
{
AttributeName: 'sid',
KeyType: 'HASH',
},
],
AttributeDefinitions: [
{
AttributeName: 'sid',
AttributeType: 'N',
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10,
},
};
dynamodb.createTable(params, function(err, data) {
if (err) ppJson(err); // an error occurred
else ppJson(data); // successful response
});
在本地 db shell 的浏览器中运行上面的代码片段
http://localhost:8000/shell/
它创建一个以“sid”作为哈希键的表。
要插入:
var params = {
TableName: 'student',
Item: { // a map of attribute name to AttributeValue
sid: 123,
firstname : { 'S': 'abc' },
lastname : { 'S': 'xyz' },
address : {'S': 'pqr' },
ReturnValues: 'NONE', // optional (NONE | ALL_OLD)
ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES)
ReturnItemCollectionMetrics: 'NONE', // optional (NONE | SIZE)
}
};
docClient.put(params, function(err, data) {
if (err) ppJson(err); // an error occurred
else ppJson(data); // successful response
});