Sending email via AWS SES within AWS Lambda function Sending email via AWS SES within AWS Lambda function node.js node.js

Sending email via AWS SES within AWS Lambda function


It would appear that I had the context.succeed(event) placed in the wrong area of code.

Once I moved it into the sendEmail callback all worked.

var aws = require('aws-sdk');var ses = new aws.SES({  accessKeyId: 'myAccessKey',  secretAccesskey: 'mySecretKey',  region: 'eu-west-1' });exports.handler = function(event, context) {  console.log("Incoming: ", event);  var output = querystring.parse(event);  var eParams = {    Destination: {        ToAddresses: ["toAddress@email.com"]    },    Message: {        Body: {            Text: {                Data: output.Key1            }        },        Subject: {            Data: "Ses Test Email"        }    },    Source: "mysource@source.com"};console.log('===SENDING EMAIL===');var email = ses.sendEmail(eParams, function(err, data){    if(err) {       console.log(err);       context.fail(err);    } else {        console.log("===EMAIL SENT===");        console.log("EMAIL CODE END");        console.log('EMAIL: ', email);        console.log(data);        context.succeed(event);    }});};


This is because Lambda freezes the container when the function exits and any async processes are frozen, such as your email. This is especially true with Node. See Lambda Programming Model. http://docs.aws.amazon.com/lambda/latest/dg/lambda-introduction.html


My case is: when you set VPC, the issue happens cause of internet limitation access.

If you remove VPC, everything works fine.

It seems a AWS bug for me.

I opened today a AWS Support for it.

No anwers yet.