SNS failed to warn about a missing variable in a SES Templated email

51 Views Asked by At

I had a SES templated email with a line looking line this:

<h6>Welcome {{usernamee}}</h6>

My emails were never being sent and it took me forever to see I had a typo in my template.

I am using AWS SDK for Java 2.x (version 2.20.153 to be exact) and the response from AWS return 200 OK.

Looking around, SNS seems to be the one would should tell me when the rendering of the email has failed. I have a SNS with a simple lambda that will tell me when the email has either bounced or been delivery successfully, but no rendering error ever surfaced

Lamda:

exports.handler = function(event, context) {
    var message = event.Records[0].Sns.Message;
    console.log('Message received from SNS:', message);
};

Here's the rest of my configuration for my SNS:

resource "aws_sns_topic" "ses_topic" {
  name = "ses-topic"
}

resource "aws_lambda_function" "ses_sns_notification_sender" {
  filename      = "lambdas/ses-sns-notification-sender.zip"
  function_name = "ses-sns-notification-sender"
  role          = aws_iam_role.iam_for_lambda.arn
  handler       = "ses-sns-notification-sender.handler"
  runtime       = "nodejs14.x"
}

resource "aws_sns_topic_subscription" "ses_sns_notification_sender_subscription" {
  topic_arn = aws_sns_topic.ses_topic.arn
  protocol  = "lambda"
  endpoint  = aws_lambda_function.ses_sns_notification_sender.arn
}

resource "aws_lambda_permission" "allow_sns" {
  statement_id  = "AllowExecutionFromSNS"
  action        = "lambda:InvokeFunction"
  function_name = aws_lambda_function.ses_sns_notification_sender.function_name
  principal     = "sns.amazonaws.com"
  source_arn    = aws_sns_topic.ses_topic.arn
}

resource "aws_ses_identity_notification_topic" "email_notification" {
  count                    = length(var.sns_notification_type) // ["Bounce", "Complaint", "Delivery"]
  topic_arn                = aws_sns_topic.ses_topic.arn
  notification_type        = var.sns_notification_type[count.index]
  identity                 = var.ses_identity
  include_original_headers = true
}
1

There are 1 best solutions below

3
MisterSmith On

Taken from the SES docs:

If you send an email that contains invalid personalization content, Amazon SES might accept the message, but won't be able to deliver it. For this reason, if you plan to send personalized email, you should configure Amazon SES to send Rendering Failure event notifications through Amazon SNS. When you receive a Rendering Failure event notification, you can identify which message contained the invalid content, fix the issues, and send the message again.