dynamodb node aws-sdk simple getItem() call
I was trying to do it as it was suggested in the documentation, but also got errors.
At the end the following worked:
var aws = require('aws-sdk');
var db = new aws.DynamoDB({
region: 'eu-central-1',
maxRetries: 1
});
exports.handler = event => {
return queryMyThings();
}
const queryMyThings = async (event) => {
var params = {
Key: {
"ColumnByWhichYouSearch": {
S: "ValueThatYouAreQueriing"
}
},
TableName: "YourTableName"
};
return await db.getItem(params).promise();
}
Must follow the SDK and Docs, its simple: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html
var params = {
AttributesToGet: [
"password"
],
TableName : 'foo',
Key : {
"username" : {
"S" : "bar"
}
}
}
db.getItem(params, function(err, data) {
if (err) {
console.log(err); // an error occurred
}
else {
console.log(data); // successful response
res.send(data);
}
return next();
});