top of page

AWS SNS message filtering to receive subset of topic messages

Updated: Oct 17, 2023

AWS SNS message filtering to receive a subset of topic messages.


Tutorial Objectives:

1. Learn to use SNS message filtering

2. Learn to implement fanout messaging pattern using SNS & SQS


Step 1: Open AWS Management Console and open Amazon SNS service console.

Give topic name as Insurance-Quote-Requests and click Next step.

ree

Choose Type: Standard and Create topic.

ree

The new topic appears on Topic details page.

ree

Step 2: Open Amazon SQS service console in new window and click Create queue.

ree

Leave Standard queue selected and name the queue as Vehicle-Insurance-Quotes.

ree

Scroll down and click Create queue.

Similarly create two additional queues named as Life-Insurance-Quotes and All-Quotes.

All three queues are now listed in the SQS console.

ree

Step 3: Select the All-Quotes queue, click Actions and select Subscribe to Amazon SNS topic.

ree

From the dropdown, select Insurance-Quote-Requests topic and click Save.

ree

Follow same step for Life-Insurance-Quotes and Vehicle-Insurance-Quotes to subscribe to topic.


Step 4: Return to the Amazon SNS console tab and click on Topics.

Click on the topic name Insurance-Quote-Requests.

ree

Scroll down you will be able to see all SQS queues subscribed to this SNS topic. Select Vehicle-Insurance-Quotes queue then click Edit.

ree

This will take you to the Edit subscription page. Click on the arrow to edit subscription filter policy.

ree

On the dialog box displayed, enter the following JSON object:

{"insurance_type": ["car", "boat"]}

Click Save changes.

ree

Now, repeat the process add filter policy to the second queue. Select the Life-Insurance-Quotes queue, click Edit.

ree

On the dialog box displayed, enter the following JSON object:

{"insurance_type": ["life"]}

Click Save changes.

ree

All-Quotes queue will catch all events published to the topic. So, there is no need to set filter policy for the subscription related to the All-Quotes queue.


Step 5: On the Insurance-Quotes-Requests Topic page, click on Publish message.

ree

Create the first message by entering the following values in the form:

· In Subject, enter: Insurance Quote Request #1

ree

· In Message structure, leave Identical payload for all delivery protocols selected

· In Message body to send to the endpoint, enter the following text to represent a car insurance quote request: 2017 Volvo S60, Montreal

ree

· In Message attributes:

· Select String in the Type field

· Enter insurance_type in the Name field

· Enter car in the Value field

· Click Publish message.

ree

You are returned to the Insurance-Quote-Requests Topic page. Click on Publish message again, and create a second message using the following values:

· In Subject, enter: Insurance Quote Request #2

ree

· In Message structure, leave Identical payload for all delivery protocols selected

· In Message body to send to the endpoint, enter the following text to represent a car insurance quote request: Male, 33 years old, Vancouver

ree

· In Message attributes:

· Select String in the Type field

· Enter insurance_type in the Name field

· Enter life in the Value field

· Click Publish message.

ree

You are returned to the Insurance-Quote-Requests Topic page. Click on Publish message again, and create a third message using the following values:

· In Subject, enter: Insurance Quote Request #3

ree

· In Message structure, leave Identical payload for all delivery protocols selected

· In Message body to send to the endpoint, enter the following text to represent a car insurance quote request: Townhouse, 1500 sq ft, Toronto

ree

· In Message attributes:

· Select String in the Type field

· Enter insurance_type in the Name field

· Enter home in the Value field

· Click Publish message.

ree

Step 6: Return to Amazon SQS console. Select the Vehicle-Insurance-Quotes queue, and click on Send and receive messages.

ree

Scroll down and click Poll for messages.

ree

ree

Click to the Message ID

Note that only one message was pushed into this queue, related to that car insurance quote (Insurance Quote Request #1). Close the dialog box.

ree

Repeat the process for the second queue. Select the Life-Insurance-Quotes queue, and click on Send and receive messages.

ree

Scroll down and click Poll for messages.

ree

Click to the Message ID.

Note that another message was pushed into this queue, related to that life insurance quote (Insurance Quote Request #2).

ree

Finally, Select the All-Quotes queue, Click Start Polling for Messages.

Note that all three messages were pushed into this queue (Insurance Quote Requests #1, #2 and #3).


ree

Step 7: Delete all the resources.

· Delete the subscription and then delete all the queues.

· Delete the topic.


Was this document helpful? How can we make this document better? Please provide your insights. You can download PDF version for reference.

We provide the best AWS training from Pune, India.

For aws certification contact us now.

11 Comments


Shruti Bhosekar
Shruti Bhosekar
Feb 19, 2024

Easy to understand..very well explained!

Like

Shreya Patne
Shreya Patne
Feb 19, 2024

Easy to understand

Like

Rucha Kulkarni
Rucha Kulkarni
Feb 19, 2024

Easy to understand

Like

Tanaya Yalrute
Tanaya Yalrute
Feb 19, 2024

Well explained

Like

VAISHNAVI M
VAISHNAVI M
Feb 16, 2024

Very useful sir

Like
bottom of page