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