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