Created
April 18, 2016 19:26
-
-
Save LosantGists/bc47ee74c7ac97f493c947b0c9567162 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
'use strict'; | |
const doc = require('dynamodb-doc'); | |
const dynamo = new doc.DynamoDB(); | |
exports.handler = (event, context, callback) => { | |
if(!event || !Array.isArray(event)){ return callback(null, null); } | |
let deviceSerial; | |
event.forEach((pair) => { | |
if(pair.key === 'deviceSerial'){ deviceSerial = pair.value; } | |
}); | |
if(!deviceSerial){ return callback(null, null); } | |
let deviceQuery = { TableName: 'deviceMapping', Key: { deviceSerial } }; | |
dynamo.getItem(deviceQuery, (err, result) => { | |
if(err){ return callback(err); } | |
if(!result.Item){ return callback(null, null); } | |
let userQuery = { TableName: 'users', Key: { id: result.Item.userId } }; | |
dynamo.getItem(userQuery, (err, result) => { | |
if(err){ return callback(err); } | |
if(!result.Item){ return callback(null, null); } | |
callback(null, result.Item); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment