Amazon SES and Lambda Functions Thumbnail

Setup Serverless Email service using AWS SES and Lambda Functions

In this video I will show you how to setup Simple Email Service (SES) and AWS Lambda function to have your receiving emails forwarded to any other destination. This tutorial builds upon the previous tutorial on configuring AWS SES as an SMTP service for your website.

Steps:

  1. Have your domain setup with AWS SES (Watch my previous video tutorial)
  2. Make sure you are in a Region that support Email Rule sets.
  3. Create a Lambda Function
    1. Goto the Lambda Service in AWS console
    2. Create Function
    3. Give your function a name “SesForwarder” and select scratch
    4. Copy the index.js code from the Github Repo of @arithmitic (GitHub – arithmetric/aws-lambda-ses-forwarder: Serverless email forwarding using AWS Lambda and SES) and paste it into the index.js edit in the Lambda screen.
    5. Modify the defaultConfig section
      1. Change from email to be the SES email address that you verified
      2. S3 Bucket
      3. Forward mapping
    6. Click on the Configuration Tab
      1. Modify the General Configuration and set the memory limit to be 128 MB or 512MB and 30 second Timeout;
      2. This is if you may have large attachments.
    7. Deploy the function
    8. Publish the function
  4. Click on Permissions
    1. Click on the Role Name. This will open the IAM
    2. Click on the Policy starts with AWSLambda….
    3. Click Edit Policy
    4. Click on JSON
    5. Copy and Paste the code at the end

{
         "Effect": "Allow",
         "Action": "ses:SendRawEmail",
         "Resource": "*"
      },
      {
         "Effect": "Allow",
         "Action": [
            "s3:GetObject",
            "s3:PutObject"
         ],
         "Resource": "arn:aws:s3:::S3-BUCKET-NAME/*"
      }

  1. Modify the S3-BUCKET-NAME with the name of your S3 bucket.
  2. Save Policy
  3. Back in SES console, modify the existing rule
    1. Add a new Lambda action under the Existing S3 Action
    2. Select the Lambda function you created.
    3. If it ask for permissions say Add Permissions.
  4. Verify email that you are forwarding to (in my case it is gmail.com) if your SES is still in Sandbox mode

Links from the tutorials