Created
December 10, 2017 10:25
-
-
Save tonkatsu7/55b90377609cf8e8c29fcc2b4aac44ce to your computer and use it in GitHub Desktop.
DynamoDB trigger publishes every record to SNS
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'; | |
console.log('Loading function'); | |
var AWS = require("aws-sdk"); | |
exports.handler = (event, context, callback) => { | |
console.log('Received event:', JSON.stringify(event, null, 2)); | |
event.Records.forEach((record) => { | |
console.log(record.eventID); | |
console.log(record.eventName); | |
console.log('DynamoDB Record: %j', record.dynamodb); | |
var eventText = JSON.stringify(record.eventID, null, 2); | |
console.log("Received event:", eventText); | |
var sns = new AWS.SNS(); | |
var params = { | |
Message: eventText, | |
Subject: "Sigfox Notification from Sandpit", | |
TopicArn: "arn:aws:sns:ap-southeast-2:769671041126:sigfoxNotifications" | |
}; | |
sns.publish(params, function(err, data) { | |
if (err) { | |
console.error("Unable to push to SNS", err.stack); | |
} else { | |
console.log("Notification pushed:", JSON.stringify(data, null, 2)); | |
} | |
}); | |
}); | |
callback(null, `Successfully processed ${event.Records.length} records.`); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment