Setup Queue & Advanced Filter Policy

In this section, you will configure the necessary infrastructure for specialized routing: create the ColdBrewExpressQueue on Amazon SQS, grant permission for Amazon SNS to publish messages via an SQS Access Policy, subscribe the queue to the CoffeeOrders topic, and establish a multi-attribute filter policy combining string prefix matching (prefix) and numeric comparison (numeric).


Create the ColdBrewExpressQueue in Amazon SQS

  1. Access the Amazon SQS Console in the Singapore (ap-southeast-1) Region.
  2. On the Queues dashboard, click the Create queue button.

Create ColdBrewExpressQueue

  1. Under Type, keep the Standard queue type.
  2. In Name, enter: ColdBrewExpressQueue.

Create ColdBrewExpressQueue

  1. Scroll down to the Access policy section, select Advanced, and paste the following permission policy (replace <YOUR_ACCOUNT_ID> with your 12-digit AWS Account ID):
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sns.amazonaws.com"
      },
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:ap-southeast-1:<YOUR_ACCOUNT_ID>:ColdBrewExpressQueue",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:sns:ap-southeast-1:<YOUR_ACCOUNT_ID>:CoffeeOrders"
        }
      }
    }
  ]
}

Save SQS Queue Policy

  1. Scroll to the bottom of the page and click Create queue.

Save SQS Queue Policy

Save SQS Queue Policy


Subscribe the Queue to the CoffeeOrders SNS Topic

  1. On the details page of ColdBrewExpressQueue, switch to the SNS subscriptions tab.
  2. Click Subscribe to Amazon SNS topic.
  3. In the Specify an Amazon SNS topic dropdown, select the CoffeeOrders topic.
  4. Click Save.

Subscribe Queue to CoffeeOrders SNS Topic

Subscribe Queue to CoffeeOrders SNS Topic

Subscribe Queue to CoffeeOrders SNS Topic


Configure the Advanced Subscription Filter Policy

  1. Navigate to the Amazon SNS Console → Select Topics → Click on CoffeeOrders.
  2. Under the Subscriptions tab, locate the subscription pointing to ColdBrewExpressQueue.
  3. Click on the subscription ID, then click the Edit button.

Locate ColdBrewExpressQueue Subscription

Locate ColdBrewExpressQueue Subscription

  1. Expand the Subscription filter policy section.
  2. Select Message attributes as the filter scope, and input the following JSON policy:
{
  "drink": [
    { "prefix": "Citrus" }
  ],
  "quantity": [
    {
      "numeric": [ ">=", 2 ]
    }
  ]
}

Configure Subscription Filter Policy

Multi-Attribute AND Logic:
When you define multiple distinct attribute keys at the top level of a Filter Policy (drink and quantity), Amazon SNS automatically combines them using a boolean AND operator. Both the specified drink name prefix and the numeric threshold must match simultaneously for the message to be delivered!

  1. Click Save changes.

Save Advanced Filter Policy

Save Advanced Filter Policy