2016-08-02 78 views
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); 
    } 
}); 

回答

2

在表定义,你被点名的关键Ref-ID但在放置操作正在命名的关键Info。如果您的表具有名为Ref-ID的散列键,则插入的每条记录都需要Ref-ID的值。

+0

感谢您的回复。我做了更改,仍然收到相同的错误。我编辑我的帖子以反映我所做的更改,也许我犯了另一个微不足道的错误? – FF5Ninja

+1

您是否在更改密钥名称后重新创建表格? –

+0

啊是的,琐碎的错误。谢谢! 现在我有一个新的错误修复大声笑 – FF5Ninja

相关问题