Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prestomation/63497eb0934960c755d7a7e927b26ddb to your computer and use it in GitHub Desktop.
Save prestomation/63497eb0934960c755d7a7e927b26ddb to your computer and use it in GitHub Desktop.
var AWS = require("aws-sdk");
var docClient = new AWS.DynamoDB.DocumentClient()
//Create a Translator object, which comes from the DocumentClient
var dynamodbTranslator = docClient.getTranslator();
//It needs a SDK 'shape'. The individual Items in the Stream record
//are themselves the same Item shape as we see in a getItem response
var ItemShape = docClient.service.api.operations.getItem.output.members.Item;
module.exports.handler = function(event, context, callback) {
event.Records.forEach(function(record) {
//Let's just replace, in-place each Item with a 'translated' version
record.dynamodb.OldImage = dynamodbTranslator.translateOutput(record.dynamodb.OldImage, ItemShape);
record.dynamodb.NewImage = dynamodbTranslator.translateOutput(record.dynamodb.NewImage, ItemShape);
//Do Stuff With Your New Sane Record
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment