Last active
September 30, 2016 20:52
-
-
Save jinman/206d72c1b14f73428594803f8fb03639 to your computer and use it in GitHub Desktop.
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 = dsn, uniqueid (hashkey for GSI), data (String/Blob) | |
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.getItem({ | |
"TableName": tableName, | |
"Key" : { | |
"dsn": { "S": event.serialNumber } | |
} | |
}, function(err, data) { | |
if (err) { | |
context.done('error getting item into dynamodb failed: '+err); | |
} | |
else { | |
console.log('great success: '+JSON.stringify(data.Item.uniqueid.S, null, ' ')); | |
context.done(null, JSON.stringify(data.Item.uniqueid.S)); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment