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

查看:25
本文介绍了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/访问 Web 控制台

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天全站免登陆