An AWS Lambda function to send emails using Amazon SES.
The primary purpose of this function is to provide a server-side back-end for sending emails from static websites.
By using AWS Lambda, we can eliminate the need to host your (almost) static website on EC2 instances.
- Create an IAM Role for executing AWS Lambda functions.
- Give your new IAM Role the following policy:
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource" : "arn:aws:logs:*:*:*"
},
{
"Effect" : "Allow",
"Action" : [
"cloudwatch:PutMetricData"
],
"Resource" : "*"
},
{
"Effect" : "Allow",
"Action" : [
"ses:SendEmail"
],
"Resource" : "*"
},
{
"Effect" : "Allow",
"Action" : [
"s3:GetObject"
],
"Resource" : "*"
}
]
}
-
Create an S3 bucket to store the email template(s).
-
Create a template file (HTML or text file). A sample file is provided in the
Templates/
folder. -
Upload the template file to your S3 bucket.
-
Download the latest release ZIP file.
-
Edit
config.js
providing your own details. Put your customized file back into the ZIP file. -
Create an AWS Lambda function using your custom ZIP file as the source code.
Call the Lambda function with any number of properties. The properties will be passed on to the template file for substitution.
email: This parameter is required. It's used to populate the "Reply-To" field of the email.
name: This parameter is optional, but when omitted, the value from email
will be used.
Template File:
<p>
Name: {{name}}<br />
Email: {{email}}<br />
</p>
<p>{{message}}</p>
Input Parameters:
{
"name": "John",
"email": "john@example.com",
"message": "This is my message"
}
The following libraries are used:
- AWS SDK for NodeJS
- Markup.js - https://github.com/adammark/Markup.js/