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.
3. INTRODUCTION
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.
PREREQUISITES
• AWS SES
• AWS SNS
• AWS S3
• AWS Lambda
REQUIREMENTS
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.
4. WORKFLOW
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.
5. Solution
Setting up Prerequisites
1) AWS SNS
Create a SNS Topic by following below steps,
Open AWS account à choose services as SNS
Click on Create Topic à give the Topic name and Display Name
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:
7. 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.
8. 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: {
Data:Subject,
Charset: 'UTF-8'
},
Body: {
Html: {
10. 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.
Implementation
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
Conclusion
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).