Skip to content

Instantly share code, notes, and snippets.

@jinman
Last active September 30, 2016 20:52
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/206d72c1b14f73428594803f8fb03639 to your computer and use it in GitHub Desktop.
Save jinman/206d72c1b14f73428594803f8fb03639 to your computer and use it in GitHub Desktop.
// 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