2016-10-05 4 views
1

Wenn ich eine Erhaltungs-Anforderung von DynamoDB mit den aws NodeJS Client das Ergebnis enthält eine Antwort mit der Art, wie der Key dhWie DynamoDB Antwort von NodeJS Client

{ 
    Item: { 
     newrelic_id: { 
      S: 'nr-1234' 
     } 
    , 
     jumpcloud_id: { 
      S: 'j-234' 
     } 
    , 
     microtime: { 
      N: '1475690490854' 
     } 
    , 
     instance_id: { 
      S: 'i-abc1234' 
     } 
    } 
} 

Beachten Sie, dass die Schlüssel zu den Werten neu zu formatieren sind die Präfixe für die Typen, S für String und N für Number Gibt es eine Möglichkeit, diesen "Typenschlüssel" zu entfernen?

+1

Ich würde empfehlen, stattdessen den DocumentClient zu verwenden, da er all das automatisch für Sie konvertiert. 'new AWS.DynamoDB.DocumentClient()' – idbehold

Antwort

2

Hier ist der Beispielcode mit DocumentClient.

var AWS = require("aws-sdk"); 

var creds = new AWS.Credentials('akid', 'secret', 'session'); 

AWS.config.update({ 
    region : "us-west-2", 
    endpoint : "http://localhost:8000", 
    credentials : creds 
}); 

var docClient = new AWS.DynamoDB.DocumentClient(); 

var table = "Movies"; 

var year_val = 2015; 
var title = "The Big New Movie"; 

var params = { 
    TableName : table, 
    KeyConditionExpression : 'yearkey = :hkey and title = :rkey', 
    ExpressionAttributeValues : { 
     ':hkey' : year_val, 
     ':rkey' : title 
    } 
}; 

docClient.query(params, function(err, data) { 
    if (err) { 
     console.error("Unable to read item. Error JSON:", JSON.stringify(err, 
       null, 2)); 
    } else { 
     console.log("GetItem succeeded:", JSON.stringify(data, null, 2)); 
    } 
}); 

Ausgang: -

Der Ausgang nicht über den Datentyp des Attributs.

GetItem succeeded: { 
    "Items": [ 
    { 
     "title": "The Big New Movie", 
     "yearkey": 2015, 
     "info": { 
     "rating": 0, 
     "plot": "Nothing happens at all." 
     } 
    } 
    ], 
    "Count": 1, 
    "ScannedCount": 1 
}