Search code examples
amazon-web-servicesiot

How to search by nested property in AWS IoT Rules using AWS IoT query language


I'm trying to get AWS IoT rules trigger my actions. But the documentation is pretty poor. For some reason documentation think i'll have json payloads with nesting level=1 top. Example of my JSON payload:

"state": { "reported": { "movement": "yes" } } }

Query i'm using inside a rule SELECT * FROM '$aws/things/thing-name/shadow/update/accepted' WHERE state.reported.movement="yes"

Documentation, i'm using: http://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-where.html

has information just about flat JSON object, i did try to use state.reported.movement, reported.movement, just movement and looks like none of them works


Solution

  • Okay, answer to my question is: AWS IoT Supports nested properties in WHERE statements. For some reason it didn't work when i did create a rule. Maybe SNS topic had some delay with delivering messages.

    My state of the thing, coming to AWS IoT accepted topic looks like that:

    {
      "state": {
        "reported": {
          "system": "armed",
          "movement": "yes"
        }
      },
      "metadata": {
        "reported": {
          "system": {
            "timestamp": 1509207282
          },
          "movement": {
            "timestamp": 1509207282
          }
        }
      },
      "version": 618,
      "timestamp": 1509207282,
      "clientToken": "xxxxxxxx"
    }
    

    And to query that JSON i'm using following query:

    SELECT * FROM '$aws/things/myThing/shadow/update/accepted' WHERE state.reported.movement="yes" and state.reported.system="armed"