mardi 6 janvier 2015

How to fetch data from DynamoDB using nodejs

I am trying to fetch an element from one of my DynamoDB table. I have used Nodejs to do this. It is fetching the element but its also fetching the element type and some other data. So, my code looks like below. I have my table as



dummyKey endTime startTime status
1 1:30:00 1:15:00 start


I want to fetch and print my endTime onto one of my geckoboard widget. But, when I console this I get { ConsumedCapacityUnits: 0.5, Item: { endTime: { S: '1:30:00' } } } text { success: true }. But, I just want 1:30:00 to be displayed so that i can push it to widget. How could this be acomplished modifying the below Nodejs code. I am new to nodejs.



var AWS = require('aws-sdk');
AWS.config.update({
region: 'us-east-1' });
var db = new AWS.DynamoDB({
apiVersion: '2011-12-05'
});
var Geckoboard = require('geckoboard-push');
var gecko = new Geckoboard({
api_key: '2335324j5n3j4b4b6h4b64k6n4l5k'
});
var text = gecko.text('XXXX-XXXXX-XXXXX-XXXXX');
var params = {
AttributesToGet: ["endTime"],
TableName: 'tableName',
Key: {
"HashKeyElement": {
"S": "1"
},
}
}
db.getItem(params, function(err, data) {
if (err) {
console.log(err); // an error occurred
} else {
text.send([{
text: data
}, ], function(err, response) {
console.log('text', response);
});
console.log(data); // successful response
}
});




Aucun commentaire:

Enregistrer un commentaire