- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
Hi janpoltan,
Today, the rules engine cannot fetch thing type, thing group, or registry attributes for a thing when processing a message. You could write a Lambda function to fetch these kinds of metadata and evaluate that at runtime with the aws_lambda() function: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-func-aws-lambda
The other way to achieve that is as you describe, with a Step Functions solution.
A third way to achieve this, if it makes sense for your solution, is to store the thing type in the device shadow. The shadow can be referenced by the rules engine at runtime today. The main concern is whether this leaks inappropriate control plane info to your data plane, or whether there is risk of your device or other actors accidentally clearing this type from the shadow.
Ryan
Ive tried using the aws_lambda
https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-func-aws-lambda
It looks like the sql dont support passing topic vars?
SELECT topic(3) as id, aws_lambda("arn:aws:lambda:eu-west-1:xxxx:function:xxxx", {"payload": id}) as deviceEnv FROM 'device/test'
or
SELECT aws_lambda("arn:aws:lambda:eu-west-1:xxxx:function:xxxx", {"payload": topic(3)}) as deviceEnv FROM 'device/test'
I'm a little surprised the second approach didn't work. If the topic() function is not evaluated first before sending the value to Lambda, you can write this in a nested way to work around:
SELECT aws_lambda("arn:aws:lambda:eu-west-1:xxxx:function:xxxx", {"payload": topic}) as deviceEnv FROM (SELECT *, topic(3) as topic FROM 'device/test')
Admittedly I did not test the above SQL, but this is how I've solved past similar issues where values needed be generated and bubbled up to a secondary query.
HTH,
Ryan
Actually the second option worked. My mistake not updating the topic filter to
device/test/+
SELECT * FROM 'device/test/+' WHERE (SELECT aws_lambda("arn:aws:lambda:region:accountId:function:functionName", {"deviceId": topic(3)}).env as env FROM 'device/test/+') = "dev"
The where clause doesnt seem to work
Edited by: janpoltan on Apr 3, 2019 1:44 AM
Contenuto pertinente
- AWS UFFICIALEAggiornata un anno fa
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata 3 anni fa