gpt4 book ai didi

node.js - 无法在 dynamodb-local 中创建表 - aws

转载 作者:太空宇宙 更新时间:2023-11-03 23:07:45 24 4
gpt4 key购买 nike

我正在使用dynamoDB-local与nodejs代码。

我有以下代码:

var aws = require("aws-sdk")
aws.config.update({"accessKeyId": "aaa",
"secretAccessKey": "bbb",
"region": "us-east-1"})

var awsdb = new aws.DynamoDB({ endpoint: new aws.Endpoint("http://localhost:8000") });

awsdb.createTable({
TableName: 'myTbl',
AttributeDefinitions: [
{ AttributeName: 'aaa', AttributeType: 'S' },
],
KeySchema:[
{ AttributeName: 'aaa', KeyType: 'HASH' }
]
}, function() {
awsdb.listTables(function(err, data) {
console.log(data)
});
});

但它没有创建表。我在日志中收到 { TableNames: [] } 。错误为空。

最佳答案

您似乎在 CreateTable 请求中缺少必需的 ProvisionedThroughput 参数。因此,发生的情况是 CreateTable 返回验证错误,而 ListTables 成功执行而不返回任何表(代码中的“err”变量似乎用于 ListTables 调用)

例如以下对我有用

var aws = require("aws-sdk")
aws.config.update({"accessKeyId": "aaa",
"secretAccessKey": "bbb",
"region": "us-east-1"})
var awsdb = new aws.DynamoDB({ endpoint: new aws.Endpoint("http://localhost:8000") });

awsdb.createTable({
TableName: 'myTbl',
AttributeDefinitions: [
{ AttributeName: 'aaa', AttributeType: 'S' },
],
KeySchema:[
{ AttributeName: 'aaa', KeyType: 'HASH' }
],
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1},
}, function(err, data) {
if (err)
console.log(err, err.stack); // an error occurred
else {
awsdb.listTables(function(err, data) {
console.log(data)
});
}
});

关于node.js - 无法在 dynamodb-local 中创建表 - aws,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28697711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com