Sending Exception Detail as Email through AWS SES

Amazon Simple Email Service (Amazon SES) is a highly scalable and cost-effective email service for developers and businesses. Amazon SES eliminates the complexity and expenditure of building an in-house email solution or licensing, installing, and operating a third-party email service for this type of email communication. In addition, the service integrates with other AWS services, making it easy to send emails from applications being hosted on AWS.


  1. AWS SES
  2. AWS SNS
  3. AWS S3
  4. AWS Lambda


When a user uploads an excel file to web console, each row data from the excel file should save into the database. If this process got failed due to some exception, the exception error message must go to the configured email Id’s.


We are using two lambda functions. One is used for uploading excel sheet to s3 bucket and another for sending exceptional email to administrator.

When we are uploading excel sheet to s3 bucket, if any failure or exception occurs in that time, Excel upload lambda function will send the error result to SNS (Simple Notification Service) and Exception email lambda function will trigger the SNS and send an exceptional email to the administrator by using SES.


Setting up Prerequisites


Create a SNS Topic by following below steps,

  1. Open AWS account à choose services as SNS
  2. Click on Create Topic à give the Topic name and Display Name
  3. Click on Create topic

2) AWS S3 Bucket

Create an AWS S3 Bucket with add permission and enable CORS configuration.

3) AWS Lambda

Two Lambda functions are required:

i) For reading excel file and saving each row data into concerned database

a)   Create the lambda function using below code:

var s3file = s3.getObject(params,function (err,data){


result.message = 'error while getting ' + key + 'from' + bucketName +' bucket name';

result.describtion = err;;


var wstream = fs.createWriteStream('/tmp/user.xlsx');

wstream.write(data.Body , function(err){



} else{


input: '/tmp/user.xlsx',

output: null,

},function(err, rest) {

if(err) {

result.message = 'error while reading the'+key+ ' file from '+bucketName;

} else{

maxCount = rest.length;

console.log('max count f rows in excel/cvs file = ' + maxCount);

ExcelData = rest;



b)   Upload the Zip file containing NodeJS Code, which holds logic for reading the excel file and pushing each row data into the concerned database by calling custom API.

c)   Map AWS Lambda Trigger to AWS S3 when putObject() method invoked inside AWS S3.


ii) To send the exception email

a)   Create lambda function using below code:

var ses = new aws.SES({

apiVersion: '2010-12-01'


// Generating params to send Email

var params = {

Destination: {},

Message: {

Subject: {


Charset: 'UTF-8'


Body: {

Html: {

Data: message,

Charset: 'UTF-8'





params.Destination.ToAddresses = [emailTOAddress];

params.Source = FromAddress;

// calling send email function

ses.sendEmail(params, function (err, data) {

if (err) {//failure message

result.message = err, err.stack;


} else {//Sucess

result.message = 'Email send successfully'; = data;





b)  Map AWS Lambda Trigger to AWS SNS topic when any exception occurs in the first lambda function i.e. while saving each row of excel file into the database.


Step 1: Upload the excel file directly into AWS S3 bucket manually or through AWS SDK

Step 2: If everything goes well, all the records from excel file will be saved into database. Else an email will go to the configured (admin) email id with exception details


Based on the configuration and given excel file, records will be saved into the database and if any exception occurs then it will go as an email to the admin (configured email).


Solutions Infini SMS gateway integration using Node.js, AWS lambda & API Gateway

AWS lambda

AWS Lambda runs your code on a high-availability compute infrastructure and performs all of the compute resource management including the operating system and server maintenance, automatic scaling and code monitoring, capacity provisioning, etc., which makes it ideal for sending messages.

Node.js Support

The AWS SDK for Node.js enables developers to build libraries and applications that use AWS services. You can use the JavaScript API in the browser and inside Node.js applications on the server.

API Gateway

Amazon API Gateway manages all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including authorization and access control, traffic management,  monitoring, and API version management.


Sending an SMS based on the request parameters through API call.


  • AWS lambda function
  • API Gateway
  • Node.js


API Gateway

The following Steps are required for implementing the above flow chart:

Step 1: Create a Lambda function using the below code.

var globalTunnel = require('global-tunnel');

var aws = require("aws-sdk");

var solutionInfiApiUrl = “” + <APIKey>;

var request = require('request');

//initializing Json request

              var Json = {};

              Json.sender = <Sender Number>;

              Json.message = <Message>;

              Json.format = 'json';

              Json.flash = 0;

              Json.sms = [];

              var receiver = {}

     =<receiver Number>;


                var body = JSON.stringify(Json);                     

              // making POST request to send SMS


                       url:  solutionInfiApiUrl,

                       body:   body

                  }, function(error, response){

                 if (error) {

                     result.message = 'Send SMS faild'

                       result.error = error ;




                   result.message = 'SMS sent Successfully to ' + phoneMumber;

                   console.log('response' +  JSON.stringify(response));




Step 2: Create an API Gateway and add mapping of above lambda function.

Step 3: Test the API through Postman (Chrome App) by passing the below request parameters.

Request Format Type:  JSON 

      Method:  POST.


 "PhoneNumber": "<ReceiverMobileNumber>",

 "ProjectName": "<ProjectName>",

 "PropertyName": "<PropertyName>"



Using solutions inifini, we can create multiple Dynamic templates as well as a static template. Hence, we can send both dynamic and static SMS through AWS for the given phone number.