-
-
Save thrinu/fa45fd1e6d9c02f01d9ab731e60a3ff2 to your computer and use it in GitHub Desktop.
Short aws lambda sample program that scans a dynamodb table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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