- Newest
- Most votes
- Most comments
Hi,
it's not possible to access device tags from IoT SQL statement, however you have several alternative options to achieve that:
-
Store the necessary key/value pairs per device in a DynamoDB table (instead of Device tsgs) and use get_dynamodb function of IoT SQL (see https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html) to enrich your message with this data in IoT rule. I recommend this option, as it causes the least operational overhead and scales very well with increasing number of the devices due to a scalability of DynamoDB (see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html).
-
Store the necessary key/value pairs per device in Device Shadow and use get_thing_shadow function of IoT SQL to enrich your message with this data in IoT rule. Knowing more about kind of data you want to store in key/value pairs would help to decide if this is a feasible option.
-
In case you decide against using DynamoDB or shadow, I suggest to store key/value pairs not in tags, but in Thing Attributes : https://docs.aws.amazon.com/iot/latest/apireference/API_ThingAttribute.html. Then you could build a Lambda function that reads the Thing Attributes using DescribeThing (https://docs.aws.amazon.com/iot/latest/apireference/API_DescribeThing.html), and then use aws_lambda function of IoT SQL to call that Lambda function and enrich your message with tag data in IoT rule. This option has two disadvantages: a/ potential scalability limits due to Transaction Per Second quotas on DescribeThing API call (350 Transactions per seconds, adjustable but not limitless) b/ Higher operational overhead as you need to develop and maintain an additional Lambda function. I recommend to consider options 1) and 2) before looking at 3)
Please let me know if that helps.
br , Andrei
Relevant content
- asked 4 years ago
- asked 2 years ago
- asked 2 months ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
Excellent thank you Andrei. I'm not familiar enough with DynamoDB and I'm not too worried about scale, so I think my best option is #2 with the Things Shadows for now. It's also useful since I've been meaning to learn how to use shadows anyway.
Could you offer some more tips considering #2? I see the attributes are associated at the thing level, not at the shadow level since a thing could have multiple shadows? If that's the case is the shadow even necessary? Couldn't I just add the attributes to the thing and leave it at that?
If I'm wrong and the attributes are defined at the shadow level then what am I missing when the only option I see on the shadow details that seems editable is the state. Am I supposed to add the attributes here?
First I want to mention that learning how DynamoDB works is probably lower effort compared to scenario of researching and designing how IoT Shadow would work for your use case. So if the effort for learning DynamoDB is what you are concerned about, you should not :)
Regarding the shadow option. Each IoT Thing has several shadows, one of them is unnamed and others are named. Please see this doc for the description of the related concepts: https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html. You could
Could you provide an example of an attributes you intend to use to better understand kind of parameters you intend to store?
Maybe you're right about DynamoDB effort. I spent some time yesterday trying to wrap my head around shadows and its a bit more involved than I thought.
Here's an example of the kind of attributes I want to follow the device and its payloads.
That kind of stuff. This originated from wanted to just indicate the payload_type for Lora devices so that my Lambda decoder could pick the correct function to properly decode the message.
I wanted to get that info to come in on the event received by Lambda
Thanks!