0
votes

I have a Basic AWS account in which we have deployed a lambda function. Also we have configured AWS SES service within the lambda function to send email (also our SES service is moved out of the sandbox & limit increased).

Approximately we are sending two emails per minute but we found that rarely we are getting mail, but most of the time we are not getting any email.

Also we tried deploying the application in two region but we found none to be successful.

Sample code

const AWS = require('aws-sdk');

//AWS Options 
const options = {
  region: 'us-east-1',
  // accessKeyId not required because of server less app (SWS policy added in role)
  // secretAccessKey not required because of server less app (SWS policy added in role)
}

const ses  = new AWS.SES(options);

const sendEmail = (sender, receivers, subject, content) => {
    console.log("Sending From", sender);
    console.log("REceiver Email", receivers);
    const promise = new Promise((resolve, reject) => {
        ses.sendEmail({
        Source: sender,
        Destination: {
            ToAddresses: receivers
        },
        Message: {
            Subject: {
            Data: subject
            },
            Body: {
            Html: {
                Data: content
            }
            }
        }
        }, (err, data) => {
        if (err) {
            console.log(err)
            reject(err)
        }
        resolve(data)
        });
    });
    return promise 
};
1
You don't need to create your own promises. You can use return ses.sendEmail(params).promise(). Are any errors being logged? What does CloudWatch Logs for this Lambda show?jarmod
Yes, I have tried return ses.sendEmail(params).promise(), But it does not solved my problem.Richardson. M
In CloudWatch Logs first two debugging console statement printed, Noting else printed like message id or error.Richardson. M
Your sendEmail function should be async. Also, you should ideally use the .promise() variants of the SDK functions, but that's not the cause. And make sure your Lambda is not timing out (the default timeout is 3 seconds).jarmod
Thank you @jarmod, I'll check timeout.Richardson. M

1 Answers

1
votes

I think there are a couple of things going on here:

  1. JavaScript functions that return promises need to be async
  2. your Lambda function may be timing out (the default is 3 seconds)