Search code examples
amazon-web-servicesaws-iot-analytics

How to get thing name from MQTT topic in AWS Iot Analytics pipeline?


I have created the following in AWS Iot Analytics:

  • Channel: Iot Core topic pattern => $aws/things/+/shadow/update/accepted
  • Pipeline: Fed from previous channel, selects attributes from message
  • Datastore to save messages

The incoming message to the channel is a shadow update/accepted and looks like this:

{
  "state": {
    "reported": {
      "active": false,
      "telemetry": {
        "temperature": 72,
        "humidity": 58,
        "occupancy": 28
      },
      "config": null
    }
  },
  "metadata": {
    "reported": {
      "active": {
        "timestamp": 1533059587
      },
      "telemetry": {
        "temperature": {
          "timestamp": 1533059587
        },
        "humidity": {
          "timestamp": 1533059587
        },
        "occupancy": {
          "timestamp": 1533059587
        }
      },
      "config": {
        "timestamp": 1533059587
      }
    }
  },
  "version": 89,
  "timestamp": 1533059587,
  "clientToken": "..."
}

I want to extract the thing name from the topic structure, which I have as a wild card here:

$aws/things/+/shadow/update/accepted

Is there any way to do this or must it be included in the message body directly if I want to use it here for processing?

Thanks.


Solution

  • Apparently this is done by enriching the payload that leaves IOT Core by adding to the SQL statement in the IOT Core Rule that transmits payloads to IOT Analytics.