我已将DynamoDB jar下载到我的本地Windows机器,并能够使用下面的命令启动服务.
java -jar DynamoDBLocal.jar -dbPath .
Run Code Online (Sandbox Code Playgroud)
我可以使用localhost:8000/shell /访问Web控制台
但是,我不知道如何创建表,有人可以给我语法和任何示例
如果我想创建具有以下细节的表,如何做和插入数据?
表:学生列:sid,名字,姓氏,地址.
感谢您的意见.
Vis*_*l R 17
文件很难理解.由于您使用的是dynamodb shell,我假设您要求使用js查询来创建表.
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
});
Run Code Online (Sandbox Code Playgroud)
在浏览器中运行上面的代码段(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
});
Run Code Online (Sandbox Code Playgroud)
lvt*_*llo 15
我建议使用 docker(但也可以运行 jar):
$ docker run -d -p 8000:8000 amazon/dynamodb-local
Run Code Online (Sandbox Code Playgroud)
然后你可以通过传入以下内容在 docker 容器中创建一个表endpoint-url:
$ aws dynamodb create-table \
--table-name UnifiedTable \
--attribute-definitions AttributeName=pk,AttributeType=S AttributeName=sk,AttributeType=S \
--key-schema AttributeName=pk,KeyType=HASH AttributeName=sk,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url http://localhost:8000
Run Code Online (Sandbox Code Playgroud)
您可以像这样检查表是否存在:
$ aws dynamodb list-tables --endpoint-url http://localhost:8000
# Output:
# {
# "TableNames": [
# "UnifiedTable"
# ]
# }
Run Code Online (Sandbox Code Playgroud)
您可以在此处查看 API 文档: http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/Welcome.html
或者您也可以用于aws-cli本地 DynamoDB 安装:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.CLI.html#Tools.CLI.UsingWithDDBLocal
| 归档时间: |
|
| 查看次数: |
14853 次 |
| 最近记录: |