Developer Guide

Creating an Amazon SNS Rule

You can define a rule that sends message data to an Amazon SNS topic. In this tutorial, you will create a rule that sends the name of the AWS IoT thing that triggered 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 left navigation pane, choose Act.

  2. On the Rules page, choose Create.

  3. Type a name for your rule.

  4. Under Message source, for Attribute type *, topic(3). For Topic filter, type $aws/things/+/shadow/update/accepted. The topic filter specifies the topics that, when a message is published to them, trigger the rule's action. The + used in the topic filter is a wildcard character that matches any thing name. The attribute appends the thing name onto the message contents.

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

  6. Under Select an action, select Send a message as an SNS push notification, and then choose Configure action. (This button is not shown in screenshot).

  7. Choose Create new topic.

  8. A new tab opens in your browser. Type a name and description for your SNS topic, and then choose Create topic.

  9. Switch to the browser tab where the AWS IoT console is open. For SNS target, choose the SNS topic you just created. For Message format, choose JSON.

  10. For IAM role name, choose Create a new role.

  11. Type a name for the role, and then choose Create a new role.

  12. Select the role you just created, and then choose Add action.

  13. Choose Create rule.

You have now created the 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 detail page, and change the device's shadow. When the Device Shadow service is notified of the change, it will publish a message on $aws/things/MySNSThing/shadow/update/accepted. Your rule is triggered and all subscribers to your SNS topic receive a message that contains your thing's name.