Level Up Your Email Game: Mastering AWS SES for Powerful Email Sending and Tracking
Ever felt like your emails are lost in the vast digital abyss, never reaching their intended recipients? Or maybe you’re tired of clunky email marketing tools that drain your resources and offer little insight into your campaigns’ effectiveness. Well, fret no more! Today, we’re diving headfirst into the world of AWS Simple Email Service (SES), a powerful and scalable solution that will transform your email game.
Imagine this you’re an e-commerce giant like Amazon, sending out millions of order confirmations, promotional offers, and personalized recommendations every day. SES empowers you to handle this massive volume with ease and efficiency, ensuring your emails reach their destination and spark engagement.
But the benefits extend far beyond behemoths like Amazon. Let’s say you run a local bakery craving more customer interaction. With SES, you can craft eye-catching newsletters announcing new treats, send out personalized birthday coupons, and even gather feedback through interactive surveys. All the while, SES meticulously tracks your email performance, providing valuable data to fine-tune your strategy and maximize your impact.
Whether you’re a budding entrepreneur or a seasoned marketer, SES empowers you to connect with your audience on a deeper level. So buckle up, grab your thinking cap, and let’s embark on a journey to master the art of email communication with AWS SES!
Personalized Cookie Cravings: AWS SES Driving Sales with Immediate Action
Imagine the delicious aroma of freshly baked cookies wafting through the air. Now imagine sending an email that captures this enticing aroma and delivers it directly to your customers’ inboxes. But instead of a generic message, it triggers a personalized action based on their previous interactions.
This is the power of using AWS SES with click tracking and immediate action. Let’s take a closer look:
Scenario: You’re a bakery owner launching a new line of gourmet chocolate chip cookies. When a customer clicks a link in your email, such as “Learn More About Cookies” SES records this event. This click information is received, sending an immediate follow-up email with a special offer on the new cookies.
Now that you understand the potential of immediate action with AWS SES, let’s delve into the technical details of setting up this scenario.
Please have a look at the following simple workflow:
Here, we will be using SES for email sending and tracking. After the mail is sent from SES, we monitor the click events using the SES Configuration Set. An event arrives at SNS (event destination of Configuration Set) as soon as it is triggered. Then, we send it to SQS. A Lambda function is triggered by polling the queue and sending the exclusive offer mail to the respective users.
Step 1: Create a SQS Queue
We are adding the SQS Queue in our architecture rather than directly integrating the SNS to Lambda because there is message persistence in SQS for a configurable period (1 minute to 14 days), while SNS delivers messages immediately and deletes them.
This makes SQS ideal for situations where messages need to be guaranteed delivery even if the recipient is unavailable when they are sent.
Go to AWS SQS → Queues → Create Queue. Choose Standard Queue, add an Access Policy for SNS and SQS communication, and keep the other configurations as default.
{
"Version": "2012-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__owner_statement",
"Effect": "Allow",
"Principal": "*",
"Action": "SQS:*",
"Resource": "arn:aws:sqs:<aws-region>:<aws-account>:<sqs-queue-name>"
},
{
"Sid": "topic-subscription-arn:aws:sns:<aws-region>:<aws-account>:<sns-topic-name>",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "SQS:SendMessage",
"Resource": "arn:aws:sqs:<aws-region>:<aws-account>:<sqs-queue-name>",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:sns:<aws-region>:<aws-account>:<sns-topic-name>"
}
}
}
]
}
Step 2: Create an SNS Topic
Create a SNS topic and configure the “Access Policy” so that SES can access the SNS Topic.
Add this access policy in the respective section.
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "stmt1689931588490",
"Effect": "Allow",
"Principal": {
"Service": "ses.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:<aws-region>:<aws-account-number>:<sns-topic-name>",
"Condition": {
"StringEquals": {
"AWS:SourceAccount": "<aws-account-number>"
},
"StringLike": {
"AWS:SourceArn": "arn:aws:ses:*"
}
}
}
]
}
Step 3: Create and Configure SNS Subscription
Along with that enable the subscription filter policy for only retrieving the “Click” events from all the events we get from the SES.
Step 4: Setting up SES Configuration Set
Create an SES Configuration Set.
After that, go inside the set and now we set the event destination. Our scenario requires only click events. So, we only select the “Click” event type. But, there are several types which you can discover over here — https://docs.aws.amazon.com/ses/latest/dg/event-publishing-retrieving-sns-contents.html
There are multiple destinations to receive SES events from which we select the Amazon SNS and SNS topic we created earlier.
Step 5: Creating a Verified Identity
We would create 2 verified identities. One would act as the sender (bakery)and the other as the receiver (consumer).
Note: By default, you can only send to email addresses that have been verified in your SES account. This is called “sandbox mode”. This is to prevent spam.
To enable “production mode”, where you can send emails to non-verified email addresses, you need to request this manually through a support ticket, which will also be examined manually by an AWS employee.
Step 6: Create an event tracking Lambda function
Create an AWS Lambda function with Python LTS version and create a role with AWSLambdaSQSQueueExecutionRole, and AmazonSESFullAccess managed policies.
After that add a SQS trigger.
Note: The SQS is attached with lambda functions as a Trigger. So, Lambda keeps on polling from the SQS to process them until it finds anything.
The polling happens from 5 lambdas per integration. So, per hour there would be (5 * 3 * 60) * 24 * 30 = 0.648 million requests. (The first 1 million SQS requests are free per month)
recordBakeryOfferClickEvents — https://gist.github.com/rajshah001/714e98922ab4fcef77cde7968f39942e
Along with this create another simple Python 3 Lambda Function which we would use to send a welcome mail.
welcomeEmailSendingFunction — https://gist.github.com/rajshah001/075098dd98b9ca148e7dc3d5b2a4d49a
Step 7: Testing!
Run the welcomeEmailSendingFunction Lambda Function to send an initial welcome mail to the consumer.
Now, Click on “Learn More About Cookies”. This will trigger a click event on the SES which will travel from SES → SQS → Lambda.
And recordBakeryOfferClickEvents Lambda will automatically get executed (because of SQS trigger) and we would receive the Exclusive Offer mail from the Bakery shop as per our interest.
Conclusion
Here in this post we dived deep into AWS SES and other integrations tools provided like SNS, and SQS for email sending and tracking. Along with that we explored a simple bakery shop email workflow implementation.
If you need help with DevOps practices, AWS, Infrastructure Optimization at your company, feel free to reach out to us at Opsnetic.
Contributed By: Raj Shah