Skip to content

Instantly share code, notes, and snippets.

@jinman
Last active September 30, 2016 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinman/eae25c1cc91f7496c2617246a6ca4be3 to your computer and use it in GitHub Desktop.
Save jinman/eae25c1cc91f7496c2617246a6ca4be3 to your computer and use it in GitHub Desktop.
LambdaToDynamoDBPut
// 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 = dsn
console.log('Loading function');
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, ' '));
dynamodb.listTables(function(err, data) {
console.log(JSON.stringify(data, null, ' '));
});
var tableName = "dsncustomer";
var datetime = new Date().getTime().toString();
dynamodb.putItem({
"TableName": tableName,
"Item" : {
"dsn": {"S": event.serialNumber },
"uniqueid": {"S": 1234 },
"date": {"S": datetime },
"clickType": {"S": event.clickType}
}
}, function(err, data) {
if (err) {
context.done('error putting item into dynamodb failed: '+err);
}
else {
console.log('great success: '+JSON.stringify(data, null, ' '));
context.done();
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment