0
AWS的新手,试图将数据放入表中。在阅读文档并试图遵循示例我遇到此验证错误。AWS - 没有给出所需密钥之一的值
One of the required keys was not given a value
我的代码:
var conf = require("/directory");
var AccessKey = 'supersecretkey';
var SecretKey = 'supersecretkey';
var tableName = conf.tableCS;
var AWS = require('aws-sdk');
console.log("Endpoint: " + conf.endpoint);
AWS.config.update({
accessKeyId: AccessKey,
secretAccessKey: SecretKey,
region: conf.region,
endpoint: conf.endpoint
});
var docClient = new AWS.DynamoDB.DocumentClient();
var file = process.argv[2];
console.log("File: " + file);
var csv = require("fast-csv");
csv.fromPath(file)
.on("data", function(data) {
// Uncomment to see CSV data
// console.log(data);
var arrayLength = data.length;
for (var i = 0; i < arrayLength; i++) {
// console.log(data[i]);
var params = {
TableName: tableName,
Key: {
RefID: data
}
};
console.log("Adding a new item...");
docClient.put(params, function(err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
}
else {
console.log("Added item:", JSON.stringify(data, null, 2));
}
});
// Looping through, now putItem into database
}
})
.on("end", function() {
console.log("done");
});
我发现this,但我不理解的range
关键部分。我在下面的代码中创建表,并且有hash
密钥,但不是range
密钥。这是我的问题吗?我会怎么做范围键?
var conf = require("/directory");
var AccessKey = 'supersecretkey';
var SecretKey = 'supersecretkey';
var tableName = conf.tableCSV;
// Take input from command line
process.argv.forEach(function(val, index, array) {
console.log(index + ': ' + val);
});
console.log("Table: " + tableName);
var AWS = require('aws-sdk');
console.log("Endpoint: " + conf.endpoint);
AWS.config.update({
accessKeyId: AccessKey,
secretAccessKey: SecretKey,
region: conf.region,
endpoint: conf.endpoint
});
var dynamodb = new AWS.DynamoDB();
var params = {
TableName: tableName,
KeySchema: [{
AttributeName: 'RefID',
KeyType: 'HASH'
}],
AttributeDefinitions: [{
AttributeName: 'RefID',
AttributeType: 'S'
}],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
};
dynamodb.createTable(params, function(err, table) {
if (err) {
console.log(err);
}
else {
console.log("TABLED CREATED");
console.log(table);
}
});
感谢您的回复。我做了更改,仍然收到相同的错误。我编辑我的帖子以反映我所做的更改,也许我犯了另一个微不足道的错误? – FF5Ninja
您是否在更改密钥名称后重新创建表格? –
啊是的,琐碎的错误。谢谢! 现在我有一个新的错误修复大声笑 – FF5Ninja