-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCourtDateLambda.js
62 lines (48 loc) · 1.93 KB
/
CourtDateLambda.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
console.log('Loading function');
var AWS = require('aws-sdk')
exports.handler = function(event, context) {
//console.log('Received event:', JSON.stringify(event, null, 2));
event.Records.forEach(function(record) {
//console.log(record.identifier.Keys.identifier.S);
//console.log(record.eventName);
//console.log('DynamoDB Record: %j', record.dynamodb.Keys.identifier);
console.log('DynamoDB Record2: %j', record.dynamodb.Keys.social.S);
var params = {
TableName: "PhoneNumbers",
Key: {
"social" : {
S: record.dynamodb.Keys.social.S
}
}
}
dynamoDB = new AWS.DynamoDB();
console.log("about to retrieve item");
dynamoDB.getItem(params, function(err, data) {
console.log("getting item " + JSON.stringify(data));
//console.log("was there an error? " + JSON.stringify(err));
if(err) console.log(err, err.stack);
else {
//console.log("HERE IS SOME DATA " + data);
var sns = new AWS.SNS();
//console.log("Retreived Data " + data);
var params = {
Message: 'There is a warrant for your arrest',
MessageAttributes: {
key1: {
DataType: 'String',
StringValue: 'Hi, Alex.'
}
},
Subject: 'You have a court date on ' + record.dynamodb.Keys.court_date + '.',
TopicArn: data.Item.topic_arn.S
};
sns.publish(params, function(err, data){
if(err) console.log(err, err.stack);
else {
context.succeed("Successfully processed " + event.Records.length + " records.");
}
})
}
});
});
}