Last active
September 30, 2016 20:54
-
-
Save jinman/eae25c1cc91f7496c2617246a6ca4be3 to your computer and use it in GitHub Desktop.
LambdaToDynamoDBPut
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 = 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