Created
December 31, 2016 18:08
-
-
Save hclewk/5b47b2aa42ee1c734e47051714e2468c to your computer and use it in GitHub Desktop.
DynamoDB Streams Events to SNS - NodeJS Lambda
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
var AWS = require('aws-sdk'); | |
AWS.config.region = 'us-east-1'; | |
var sns = new AWS.SNS(); | |
exports.handler = function(event, context) { | |
var count = event.Records.length; | |
var completed = function(err, data){ | |
count--; | |
if (err) { | |
console.log(data); | |
console.log(err.stack); | |
return; | |
} | |
}; | |
for(var i = 0; i < event.Records.length; i++){ | |
sns.publish({ | |
Message: JSON.stringify(event.Records[i]), | |
TopicArn: 'arn:aws:sns:SNS-ARN-HERE' | |
}, completed); | |
} | |
var start = new Date().getTime(); | |
var checkComplete = function(){ | |
var elapsed = new Date().getTime() - start; | |
if(count <= 0){ | |
context.succeed('Function Finished!'); | |
} | |
else { | |
setTimeout(checkComplete, 10); | |
} | |
}; | |
checkComplete(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment