I'm setting up a simple NodeJS Lambda function on AWS to send emails.
The code below is working when I run it locally. I have received all the credentials from AWS, verified both sender and recipient emails and granted all permissions to SES for my Lamba
const aws = require("aws-sdk");
const config = require('../config')
aws.config.update({
accessKeyId: config.mailUser,
secretAccessKey: config.mailPassword,
region:'us-east-1'
});
const ses = new aws.SES({apiVersion: '2010-12-01'});
const sendEmail = async (mailOptions) => {
const {
from,
to,
subject,
html
} = mailOptions
console.log('foo')
ses.sendEmail({
Source: from,
Destination: {
ToAddresses: [to]
},
Message: {
Subject: {
Data: subject,
Charset: 'UTF-8'
},
Body: {
Html: {
Data: html,
Charset: 'UTF-8'
}
}
}
},
(err, data) => {
console.log('baz')
if (err) {
console.error(err);
} else {
console.log('Email sent:');
console.log(data);
}
});
};
console.log('bar')
module.exports = {
sendEmail
};
It seems that ses.sendEmail()
never fires when the function is deployed - I get foo
and bar
in the CloudWatch logs but never baz
. Again, everything is running smoothly if run locally.
What is it that I am missing?
ses.sendMail()
callback – Ivan Makarov