Skip to content

Instantly share code, notes, and snippets.

@markusklems
Created January 19, 2015 23:46
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save markusklems/f50aec9901e9c8a7332a to your computer and use it in GitHub Desktop.
Save markusklems/f50aec9901e9c8a7332a 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!");
}
});
};
@kenanscott
Copy link

Thanks!

@aenugav
Copy link

aenugav commented Aug 3, 2017

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