Created
January 19, 2015 23:46
-
-
Save markusklems/f50aec9901e9c8a7332a to your computer and use it in GitHub Desktop.
Short aws lambda sample program that scans a dynamodb table
This file contains 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!"); | |
} | |
}); | |
}; |
Thanks for the sample file! Can you point to a link/doc where the details on accessing dynamodb through nodeJS is available.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!