AWS - One of the required keys was not given a value

匿名 (未验证) 提交于 2019-12-03 01:36:02

问题:

New to AWS, trying to put data into a table. After reading the documentation and trying to follow examples I am running into this validation error.

One of the required keys was not given a value 

My code:

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

I found this, but am not understanding the range key part. I'm creating the table in this following code and have the hash key, but not a range key. Is that my issue? What would I make the range key?

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

回答1:

In the table definition, you named the key Ref-ID but in your put operation you are naming the key Info. If your table has a hash key named Ref-ID then every record you insert will require a value for Ref-ID.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!