My lambda function written in node.js is quite simple. Lambda is called when new entry appear in dynamo db, then I want to loop through each entry and send an email. For some reason I can't understand why ses.SendEmail function is never called. I placed logs inside it but nothing appear in logs. I obfuscated email just for the purpose of the question (I am using actual correct email on aws).
console.log('Loading function');
var aws = require('aws-sdk');
var ses = new aws.SES({region: 'eu-west-2'});
//var nodemailer = require('nodemailer');
exports.handler = async (event, context, callback) => {
//console.log('Received event:', JSON.stringify(event, null, 2));
event.Records.forEach((record) => {
if(record.eventName == 'INSERT')
{
console.log(record.eventID);
console.log(record.eventName);
console.log('DynamoDB Record: %j', record.dynamodb);
var params = {
Destination: {
ToAddresses: ["test@***.com"]
},
Message: {
Body: {
Text: { Data: "Test"
}
},
Subject: { Data: "Test Email"
}
},
Source: "info@***.com"
};
console.log("About to send email");
ses.sendEmail(params, function (err, data) {
console.log("inside email"); // not logging
if (err) {
console.log(err);
context.fail(err);
} else {
console.log(data);
context.succeed(event);
}
});
}
});
//return `Successfully processed ${event.Records.length} records.`;
};