I am trying to send an email from a Lambda Node.js application:
mail-service.js
const ses = new aws.SES({
region: 'eu-west-1'
});
exports.send = (to, subject, text) => {
const deferred = Q.defer();
const eParams = {
Destination: {
ToAddresses: [to]
},
Message: {
Body: {
Text: {
Data: text
}
},
Subject: {
Data: subject
}
},
Source: to
};
console.log("Sending mail %s", JSON.stringify(eParams));
const email = ses.sendEmail(eParams, function(err, data){
if(err){
deferred.reject(err);
}
else {
deferred.resolve(data);
}
});
return deferred.promise;
}
When this service is called it throws at NetworkingError:
index.js:
mailService.send(process.env.EMAIL_TO, subject, text)
.then( (response) => {
console.log("SES response: %s", response);
})
.fail( (err) => {
console.log("SES err: %s", err);
});
Error: SNS err: NetworkingError: connect ECONNREFUSED 127.0.0.1:8000
How can I fix it?
Notice I have configured a IAM policy associated to the lambda's role to allow sending emails:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "xxxxxxxxxx",
"Effect": "Allow",
"Action": [
"ses:SendEmail",
"ses:SendRawEmail"
],
"Resource": [
"*"
]
}
]
}
The problem was there was a dev profile that configured AWS sdk to work with a local DynamoDB:
AWS.config.update({
region: "eu-west-2",
endpoint: "http://localhost:8000"
});
I removed the endpoint key and now it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.