I'm getting some upload errors when i try to upload my json file to dynamodb but can't seem to figure it out. The errors I get are these:
"errors": [
{
"message": "Expected params.Item['lastname'] to be a structure",
"code": "InvalidParameterType",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '0' found in params.Item['lastname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '1' found in params.Item['lastname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '2' found in params.Item['lastname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '3' found in params.Item['lastname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '4' found in params.Item['lastname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '5' found in params.Item['lastname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '6' found in params.Item['lastname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Expected params.Item['firstname'] to be a structure",
"code": "InvalidParameterType",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '0' found in params.Item['firstname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '1' found in params.Item['firstname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '2' found in params.Item['firstname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.907Z"
},
{
"message": "Unexpected key '3' found in params.Item['firstname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '4' found in params.Item['firstname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '5' found in params.Item['firstname']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Expected params.Item['employeeid'] to be a structure",
"code": "InvalidParameterType",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '0' found in params.Item['hrs']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '1' found in params.Item['hrs']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '2' found in params.Item['hrs']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '3' found in params.Item['hrs']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '4' found in params.Item['hrs']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '5' found in params.Item['hrs']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
},
{
"message": "Unexpected key '6' found in params.Item['hrs']",
"code": "UnexpectedParameter",
"time": "2016-10-20T19:16:11.908Z"
}
],
"time": "2016-10-20T19:16:11.908Z"
}
my data file that I"m trying to upload looks like this:
[
{
"lastname": "abc",
"firstname": "dfx",
"employeeid": 78,
"hrs": [
{
"availhrs": "123",
"ttlhrs": "111",
"bllhrs": "98",
"rto": "16",
"ondeckhrs": "0",
"nonbllhrs": "0",
"employeeid": 78,
"dtmonth": "2016-01-01T00:00:00.000Z",
"clientid": 1,
"clientId": 1,
"employeeId": 78
}
]
}
]
I created my table like this:
var params = {
TableName : "ach3",
KeySchema: [
{ AttributeName: "employeeid", KeyType: "HASH" }, //Sort key
{ AttributeName: "lastname", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "lastname", AttributeType: "S" },
{ AttributeName: "employeeid", AttributeType: "N" }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
};
and this is how I'm trying to upload the table:
var allACH = JSON.parse(fs.readFileSync('ach.json', 'utf8'));
allACH.forEach(function(movie) {
var params = {
TableName: "ach3",
Item: {
"lastname": movie.lastname,
"firstname": movie.firstname,
"employeeid": movie.employeeid,
"hrs": movie.hrs
}
};
dynamodb.putItem(params, function(err, data) {
if (err) {
console.error("Unable to add item", movie.employeeid, ". Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("PutItem succeeded:", movie.employeeid);
}
});
});
答案 0 :(得分:2)
The "Item" object needs to have the type information per property: So you need something like
Item: {
"lastname": {S: movie.lastname},
"firstname": {S: movie.firstname},
"employeeid": {S: movie.employeeid},
"hrs": {N: String(movie.hrs) }
}
This is telling the API that "lastname" is of type string (S).
Hope that helps