-
Notifications
You must be signed in to change notification settings - Fork 301
/
Lambda Trigger code
40 lines (40 loc) · 1.03 KB
/
Lambda Trigger code
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
const aws = require("aws-sdk");
const sns = new aws.SNS({
region:'us-east-1'
});
var ses = new aws.SES({
region: 'us-east-1'
});
exports.handler = function(event, context, callback) {
console.log("AWS lambda and SNS trigger ");
console.log(event);
const s3message = "Bucket Name:"+event.Records[0].s3.bucket.name+"\nLog details:"+event.Records[0].s3.object.key;
console.log(s3message);
var eParams = {
Destination: {
ToAddresses: ["[email protected]"]
},
Message: {
Body: {
Text: {
Data:s3message
}
},
Subject: {
Data: "cloudtrail logs"
}
},
Source: "[email protected]"
};
var email = ses.sendEmail(eParams, function(err, data) {
if (err) console.log(err);
else {
console.log("===EMAIL SENT===");
console.log("EMAIL CODE END");
console.log('EMAIL: ', email);
context.succeed(event);
callback(null, "email is send");
}
});
};
```