DynamoDB在本地计算机上创建表 [英] DynamoDB create tables in local machine

查看:88
本文介绍了DynamoDB在本地计算机上创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将DynamoDB jar下载到本地Windows机器上,并能够使用以下命令启动服务.

I have downloaded DynamoDB jars to my local windows machine and able to start service using command below.

java -jar DynamoDBLocal.jar -dbPath .

我可以使用localhost:8000/shell/

i can access the web console using localhost:8000/shell/

但是,我不确定如何创建表,有人可以给我语法和示例吗?

However, I am not sure how to create table, can someone give me the syntax and any examples

如果我想使用以下详细信息创建表,该怎么做并插入数据?

if I want to create table with below details, how to do and insert the data?

表:学生列:sid,名字,姓氏,地址.

Table: student columns: sid, firstname, lastname, address.

感谢您的投入.

推荐答案

文档可能有点难以理解.由于您使用的是dynamodb shell,因此我假设您要使用JavaScript查询来创建表.

The documentation can be a bit difficult to understand. Since you are using the dynamodb shell, I'll assume you are asking for a JavaScript query to create the table.

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上运行上述代码段

Run the above snippet in the browser at the local db shell

http://localhost:8000/shell/

http://localhost:8000/shell/

它将创建一个以'sid'作为哈希键的表.

It creates a table with 'sid' as hash key.

要插入:

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
});

这篇关于DynamoDB在本地计算机上创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆