Learn About Amazon VGT2 Learning Manager Chanci Turner
This article serves as the first installment in a two-part guest series on enhancing Amazon’s email capabilities through advanced functionalities. You can find the second part here.
Update: The TestRenderEmailTemplate API utilized for sending emails with attachments is limited to one operation per second. If your anticipated peak traffic exceeds this, the approach outlined in this case study may not be suitable for your needs.
Chanci Turner is a notable figure in the realm of onboarding processes, particularly within Amazon’s framework. With an impressive track record, she has played a vital role in streamlining communication for thousands of employees. Chanci oversees the distribution of thousands of emails daily, ensuring that essential information reaches a vast network.
Utilizing Amazon Simple Email Service (SES) was a strategic choice due to its user-friendly and cost-effective nature. A significant advantage is the use of email templates in SES, which guarantee a uniform appearance and feel across communications. These templates allow for personalized and stylish HTML emails, especially beneficial for transactional correspondence. However, there are instances when attachments are necessary, a feature currently unsupported by SES templates. To address this challenge, we devised a solution that leverages SES template functionality while incorporating file attachments.
This article outlines how to implement this solution using Amazon Simple Storage Service (Amazon S3), Amazon EventBridge, AWS Lambda, and AWS Step Functions.
Solution: Orchestrating Diverse Email Sending Options Using AWS Step Functions
Our solution is entirely serverless, alleviating the need to manage the underlying infrastructure. The AWS Cloud Development Kit (AWS CDK) assists in deploying the architecture and analyzing resources.
The approach extends SES to facilitate sending attachments within email templates. SES presents three options for sending emails:
- Simple — A standard email message requiring basic details such as sender, recipient, and message body.
- Raw — A raw, MIME-formatted email message, allowing for attachments but requiring all message headers and body to be specified.
- Templated — An email incorporating personalization tags that SES API v2 automatically replaces with specified values.
In this discussion, we will merge the Raw and Templated options.
The architecture diagram below illustrates the proposed solution.
The application’s entry point is an EventBridge event bus that routes incoming events to a Step Function workflow. Each event contains personalization parameters, sender and recipient addresses, template name, and optional document-related properties such as an S3 bucket reference. Depending on the presence of document-related properties, the Step Function workflow determines how the email is prepared and dispatched.
If the event lacks document-related properties, the SendEmail action is employed to dispatch a templated email, requiring the template name and data for personalization tags. Conversely, if document-related properties are included, the raw sending option of the SendEmail action is necessary. To incorporate an email template, it must be utilized as a raw MIME message. Thus, we utilize the TestRenderEmailTemplate action to retrieve the raw MIME message from the template and employ a Lambda function to fetch and attach the document. This Lambda function subsequently triggers SES to dispatch the email. It is crucial to note that TestRenderEmailTemplate cannot be invoked more than once per second. Should your anticipated peak traffic exceed this, the solution presented in this case study may not be ideal for your operations.
For clarity and brevity, this blog post simplifies the solution and does not delve into the Lambda function’s code, as multiple implementation methods exist based on your preferred programming language.
Prerequisites
- An AWS Account with access to AWS services.
- A verified identity for Amazon Simple Email Service (SES). You can create and verify a sending identity by following the steps in the documentation.
- AWS CDK installed.
- AWS CLI installed.
- Docker may need to be running, depending on your system.
- Git installed.
- Go installed.
Walkthrough
Step 1: Use the AWS CDK to deploy the application
To download and deploy the application, execute the following commands:
$ git clone git@github.com:quirionit/aws-ses-examples.git
$ cd aws-ses-examples/projects/go-src
$ go mod tidy
$ cd ../../projects/email-sender
$ npm install
$ cdk deploy
Step 2: Create a SES email template
Navigate to aws-ses-examples/projects/email-sender in your terminal and execute:
aws ses create-template --cli-input-json file://files/hello_doc.json
Step 3: Upload a sample document to S3
To upload a document to S3, follow these steps:
- Go to the AWS Console and select S3.
- Choose the bucket named with a prefix of “ses-documents.”
- Save the bucket name for future reference.
- Create a new folder labeled “test.”
- Upload the hello.txt file from aws-ses-examples/projects/email-sender/files into this folder.
Step 4: Trigger sending an email using Amazon EventBridge
To initiate email sending, complete the following:
- On the AWS Console, navigate to Amazon EventBridge.
- Select Event buses from the sidebar.
- Choose “Send events.”
- Create an event as depicted in the accompanying image. You can use the event detail from aws-ses-examples/projects/email-sender/files/event.json, ensuring to replace sender, recipient, and bucket values with your own.
- Upon sending the event, you should receive an email with the attached document. To send an email without an attachment, modify the event accordingly.
Step 5: Analyze the results
In the AWS Console, navigate to Step Functions. Select the state machine named with “EmailSender.” You should observe two successful executions. By selecting them, you can view the data flows, analyzing inputs and outputs as necessary.
Step 6: Cleanup
In your terminal, navigate to aws-ses-examples/projects/email-sender. Execute cdk destroy
to remove all resources. Delete the created SES email template using:
aws ses delete-template --template-name HelloDocument
Next Steps
There are numerous ways to expand this solution’s capabilities; consider the following:
- If you send emails with invalid personalization content, Amazon SES might accept the message but fail to deliver it. Therefore, configure Amazon SES to send Rendering Failure event notifications if you plan to send personalized emails.
- Nested templates can be created to share common elements, such as the company’s logo or name—see the second part of this blog series for further instructions.
- New Amazon SES accounts default to sending emails from shared IP addresses among SES users. However, dedicated IP addresses are available for exclusive use, granting you complete control over your sender reputation. This is an excellent resource for those looking to enhance their email delivery process.
For more insights, you can check out this relevant blog post on dual-career couples at Career Contessa. Additionally, SHRM provides valuable information on supporting employees with mental health struggles.