Skip to content

Instantly share code, notes, and snippets.

@thrinu
Forked from markusklems/lambda-dynamodb-scan
Created June 19, 2018 10:48
Show Gist options
  • Save thrinu/fa45fd1e6d9c02f01d9ab731e60a3ff2 to your computer and use it in GitHub Desktop.
Save thrinu/fa45fd1e6d9c02f01d9ab731e60a3ff2 to your computer and use it in GitHub Desktop.
Short aws lambda sample program that scans a dynamodb table
// create an IAM Lambda role with access to dynamodb
// Launch Lambda in the same region as your dynamodb region
// (here: us-east-1)
// dynamodb table with hash key = user and range key = datetime
console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = function(event, context) {
var tableName = "chat";
dynamodb.scan({
TableName : tableName,
Limit : 10
}, function(err, data) {
if (err) {
context.done('error','reading dynamodb failed: '+err);
}
for (var i in data.Items) {
i = data.Items[i];
console.log(i.user.S + ': '+ i.msg.S);
context.done(null, "Ciao!");
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment