Calvin's Blog

A Simple AWS SES Terraform Module For Application Email Services

∙ aws∙ ses∙ iam∙ terraform
article meme

Motivation

I needed to enable an application hosted in AWS to send email. I wanted to also add the capability to receive email sent to any address on the applications domain and store it for processing. I published the resulting terraform module to the terraform registry here. Here is a direct link to the GitHub repository.

Module Details

This module creates an SES verified identity and sets up the various Route 53 records for SES integration. This works under the assumption that the email you want to send email from is registered in Route 53 as a hosted zone.

Optionally if configured to do so you can also receive email by setting the enable_incoming_email variable to true. This will create an S3 bucket to receive the email in. There are many other options than storing in S3, but for my purposes it fit my needs at this time.

This module adds SPF, DKIM and DMARC. All of those are modern email security technologies that I may write about in the future. I have written about DKIM before here.

Partial Email / SES Primer

There are a few terms related to email and specifically AWS SES that are useful to understand if you are unfamiliar with them:

Email Terms

AWS SES Terms

A Quick note about AWS SES Sandbox

AWS accounts start with SES Sandbox access which restricts your ability to send emails via SES. You can request production access which will list these restrictions, but be aware that you will needs to make the request for production SES access to send email without the sandbox restrictions. Requesting SES Production access can be done via the AWS Console or the AWS CLI.

You can test that this works via the AWS CLI. This example assume your mail domain is example.com. You will need to change that email domain to your actual email domain ;-)

aws ses send-email --from test_sender@exmaple.com --to user@exmaple.com --text "This is a test message" --subject "This is the subject"

The example in the terraform repository also has an example of a role that can be assumed to send email via SES that restricts the sender domain.

Future Plans

This is a simple module and it suits the needs for what I needed when I wrote it. There is some potential to enhance the module to add other receive handlers than the S3 bucket like a Lambda or SNS topic message. If someone opens a PR or I ever have a need those enhancements can get added.