Bootstrap FreeKB - Amazon Web Services (AWS) - Getting Started with Simple Notification Service (SNS) Dead Letter Queue
Amazon Web Services (AWS) - Getting Started with Simple Notification Service (SNS) Dead Letter Queue


By default, after you subscribe to a Simple Notification Service (SNS) Simple Notification Service (SNS) Topic, the redrive policy to have undeliverable messages put onto a Simple Queue Service (SQS) Dead Letter queue is not enabled. 

For example, let's say I want undeliverable messages put onto a Simple Queue Service (SQS) Queue my-queue.

 

On the Access Policy tab of the Queue, let's updated the Access Policy with the following Resource-Based Permission Policy using the actual Amazon Resource Number (ARN) of your queue and your topic. This allows the Simple Notification Service sns.amazonaws.com to SendMessages to the Topic.

{
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sns.amazonaws.com"
      },
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:us-east-1:123456789012:my-queue",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:sns:us-east-1:123456789012:my-topic"
        }
      }
    }
  ]
}

 

For proof of concept, I created an @yahoo.com email address and subscribed to the Simple Notification Service (SNS) Topic.

 

By default, when subscribing to a Simple Notification Service (SNS) Topic, the redrive policy (dead-letter queue) is optional, and if not configured, is not setup. Let's select Edit.

 

Then enter the Amazon Resource Number (ARN) of your Simple Queue Service (SQS) Queue and select Save changes.

 

Be aware that the console may display the following. This Stack Overflow post mentions "Seems like the functionality is working even if it shows an alert in console. The messages get sent to DLQ on lambda failures even though the console shows an alert." So, if you get this alert, let's just carry on and test to see if messages get delivered to the dead-letter queue.

 

The aws sns publish command can be used to publish a message to the topic.

~]$ aws sns publish --subject Hello --message World --topic-arn arn:aws:sns:us-east-1:123456789012:my-topic
{
    "MessageId": "3756dea6-80cd-5e4a-ba9a-80a33a856481"
}

 

And the message got delivered to the subscribers inbox. So far, so good!

 

And there should be 0 messages in the dead letter queue since the message was successfully delivered.

 

I then deleted the @yahoo.com email address.

 

The aws sns publish command can be used to publish another message to the topic and the message should get delievered to the dead-letter queue since the message can no longer be delivered to the @yahoo.com email that was deleted.

~]$ aws sns publish --subject Hello --message World --topic-arn arn:aws:sns:us-east-1:123456789012:my-topic
{
    "MessageId": "3756dea6-80cd-5e4a-ba9a-80a33a856481"
}



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 0b3795 in the box below so that we can be sure you are a human.