I'm trying to use the amazon-ses service on a aws-lambda in order to send an email to verified recipients.
I'm following this simple tutorial which shows a simple nodejs function:
var aws = require('aws-sdk');
var ses = new aws.SES({region: 'us-east-1'});
exports.handler = (event, context, callback) => {
var params = {
Destination: {
ToAddresses: ["recipientEmailAddress"]
},
Message: {
Body: {
Text: { Data: "Test" }
},
Subject: { Data: "Test Email" }
},
Source: "sourceEmailAddress"
};
ses.sendEmail(params, function (err, data) {
callback(null, {err: err, data: data});
if (err) {
console.log(err);
context.fail(err);
} else {
console.log(data);
context.succeed(event);
}
});
};
The following policy is part of the lambda's role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ses:SendEmail"
],
"Resource": "*"
}
]
}
For some reason, this lambda function fails to send any emails and it doesn't provide any status information inside the function's CloudWatch Log group:
REPORT RequestId: XXX Duration: 534.59 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 117 MB
Any help would be appreciated.
EDIT: I work in sandbox-mode
and both source and recipient are verified emails from the region mentioned in the code (It is also reflected in the logs - no errors being thrown).
I Found the following questions in SO - but no relevant answer to my case:
Sending email via AWS SES within AWS Lambda function
callback(null, {err: err, data: data});
to the last, afterelse
block to see what will be throw out. – hoangdv