gpt4 book ai didi

javascript - AWS - 一个必需的键没有被赋予值

转载 作者:行者123 更新时间:2023-11-30 07:34:20 25 4
gpt4 key购买 nike

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);
}
});

最佳答案

在表定义中,您将键命名为 Ref-ID,但在您的 put 操作中,您将键命名为 Info。如果您的表有一个名为 Ref-ID 的哈希键,那么您插入的每条记录都需要一个 Ref-ID 的值。

关于javascript - AWS - 一个必需的键没有被赋予值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38724322/

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