SNS End Point

Our primary goal is to process only orders from US locations (us-west or us-east) that are lab-supplies using a Amazon SNS target (Orders). Similar to the previous use case, but using SNS.

let's go for it!!

Implement an EventBridge rule to target SNS

Use the EventBridge Console to:

  1. Add a rule to the Orders event bus with the name "USLabSupplyRule"

  2. With an event pattern to match events with a detail location in us-west or us-east, and a detail category with lab-supplies.

     {
       "source": [
         "com.aws.orders"
       ],
       "detail": {
         "location": [
           "us-west",
           "us-east"
         ],
         "category": "lab-supplies"
       }
     }
    
  3. Target the Orders SNS topic.

    Rule for SNS Topic

    Here, is the sample event to refer :

     {
         "version": "0",
         "id": "6e6b1f6d-48f8-5dff-c2d2-a6f22c2e0086",
         "detail-type": "Order Notification",
         "source": "com.aws.orders",
         "account": "111111111111",
         "time": "2020-02-23T15:35:41Z",
         "region": "us-east-1",
         "resources": [],
         "detail": {
             "category": "lab-supplies",
             "value": 300,
             "location": "us-east"
         }
     }
    

Send test US Orders events

Note : One of the following events should match the event rule pattern and one should not. Use CloudWatch Logs to verify events that were successfully sent to EventBridge but were not delivered to the target.

To verify our event is reached to it's desired destination (SNS Topic) we'll generate an event using Event Generator and send the following "Order Notification" events from the source "com.aws.orders":

{ "category": "lab-supplies", "value": 415, "location": "us-east" }

{ "category": "office-supplies", "value": 1050, "location": "us-west", "signature": [ "John Doe" ] }

Verify SNS topic

If the event sent to the Orders event bus matches the pattern in your rule, then the event will be sent to the Orders SQS Queue (via Orders SNS Topic).

  1. Open the AWS Management Console for SQS in a new tab.

  2. On the SQS homepage, select the Orders queue.

    Orders Queue

  3. Select the Send and receive messages button.

    SNS2

  4. Select Poll for Messages and verify the first message was delivered and the second was not.

    SQS1

    SQS2

  5. To clean up, select the event, select the Delete button, and select the Delete button again on the Delete Messages confirmation dialog.

    Delete1

Note :

If you are not seeing your messages in SQS Queue then their can be few reasons that you should check :

  1. Check if the rule is correctly associated with the SNS topic and the SQS queue. Confirm that the ARN of the SNS topic in the rule is correct and that the SQS queue is correctly specified as the target of the rule.

  2. Verify that the event pattern in the rule matches the events generated. The events must match the event pattern for the rule to trigger and send messages to the SQS queue.

  3. Ensure that the SNS topic has sufficient permissions to publish messages to the SQS queue. You can check this in the SNS topic's access policy.

  4. Confirm that the SQS queue has sufficient permissions to receive messages from the SNS topic. You can check this in the SQS queue's access policy.

  5. Make sure that the SQS queue is not configured to delay delivery of messages. If it is, messages will not be immediately available in the queue.

  6. Check if there are any errors in the CloudWatch logs. This could indicate a problem with the rule or the target.

Congratulations, We have successfully completed our SNS Challenge.