My device collects some data and sends it AWS using its IoT MQTT interface. My lambda reads the data and saves it to DynamoDB. Below is one sample record in my dynamo, where timeStamp is a primary partition key.
Item{3}
message String: DOWN
payloadMap{4}
direction String: -
message String: DOWN
timeStamp String: 2018-08-30 07:18:09.247373
value String: -70.0000
timeStamp String: 2018-08-30 07:18:09.247373
Then I am trying to query dynamo back on my small node app and I cannot access the data using below script:
dynamodb.getItem({
TableName: 'myTableName',
Key: {
'timeStamp' : {'S': '2018-08-30 07:18:09.247373'}
}
},(err,result)=>{
if(err){
console.log(err);
}
else {
console.log('success');
}
});
Below is my dynamoDB initialization:
function initDynamoAWS(){
AWS.config.apiVersion = {dynamodb: '2012-08-10'};
AWS.config.update({accessKeyId:access_key_id,
secretAccessKey:secret_access_key,
region:'us-west-2'});
dynamodb = new AWS.DynamoDB({ARN:ARN});
}
All credentials are fine as I can get dynamodb.describeTable with all the details but I cannot get a single item from my table but all I can get is "Error: The provided key element does not match the schema". What am I missing ?
When I changed the code to:
let params = {};
let key = {'timeStamp' :'2018-08-30 07:18:09.247373'};
params.TableName = 'myTableName';
params.Key = key;
dynamodb.getItem(params,(err,result)=>{
if(err){
// debugger;
console.log(err);
}
else {
console.log('success');
}
});
I am getting a different error: "InvalidPatemeterType: Expected params.Key['timeStamp'] to be a structure" "UnexpectedPatameter: Unexpected key '0' found in params.Key['timeStamp']"...and the same error for numbers up to 25.
I can get below details about my table from AWS via "describe table"
Table : AttributeDefinitions :
Array(2)
0 : AttributeName : "message"
AttributeType : "S"
1 : AttributeName : "timeStamp"
AttributeType : "S"
ItemCount : 42
TableSizeBytes : 5434 TableStatus : "ACTIVE"
KeySchema:
Array(2)
0:{AttributeName: "timeStamp", KeyType: "HASH"}
1:{AttributeName: "message", KeyType: "RANGE"}