Creating an Amazon SNS rule - AWS IoT Core

Creating an Amazon SNS rule

You can define a rule that sends message data to an Amazon SNS topic.

In this tutorial, you create a rule that sends the name of the AWS IoT thing that initiated the rule to all subscribers of an Amazon SNS topic.

To create a rule with an SNS action

  1. In the AWS IoT console, in the navigation pane, choose Act.

  2. On the Rules page, choose Create.

  3. Enter a name and brief description for your rule.


    We do not recommend the use of personally identifiable information in rule names or descriptions.

  4. In the Rule query statement editor, enter the following:

    SELECT *, topic(3) as thing FROM '$aws/things/+/shadow/update/accepted'

    (The topic filter following the "FROM" specifies the topics that initiate the rule's action when a message is published to them. The plus sign (+) used in the topic filter is a wildcard character that matches any thing name. The "topic(3)" attribute following "SELECT" appends the thing name, which is the third topic field, onto the message contents.)

  5. In Set one or more actions, choose Add action.

  6. Under Select an action, choose Send a message as an SNS push notification, and then choose Configure action.

  7. On the Configure action page, for SNS target, choose Create.

  8. Enter a topic name in the dialog box, and then choose Create.

  9. On the Configure action page, for SNS target, choose the SNS topic you just created. For Message format, choose RAW. Under Choose or create a role to grant AWS IoT access to perform this action, choose Create Role.

  10. Enter a name for the role, and then choose Create role.

  11. In Configure action, choose Add action.

  12. Choose Create rule.

To test the rule, add a subscription to the SNS topic you created, and update the shadow of any AWS IoT thing.

You can use the AWS IoT console to find a thing, open its details page, and change the device's shadow. When the Device Shadow service is notified of the change, it publishes a message on $aws/things/MySNSThing/shadow/update/accepted. Your rule is initiated and all subscribers to your SNS topic receive a message that contains your thing's name.