Trigger a lambda function based on thing type

0

How do you i trigger a lambda function based on a thing type? For example add a rule whenever a device shadow was updated. My use case is, having two cloudformation stacks for dev and staging.
All lambda functions are tagged specifically per stack. (Eg shadow-update-dev, shadow-update-staging). I'm thinking to add a attribute or type for a thing, and create an IOT rule to trigger what tag function it should trigger.

Should i just create a placeholder lambda that checks the thing type and trigger whats the corresponding lambda function? Is a step function a good match for this?

已提问 5 年前427 查看次数
6 回答
0

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

AWS
Ryan_B
已回答 5 年前
0

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'
已回答 5 年前
0

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

AWS
Ryan_B
已回答 5 年前
0

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

已回答 5 年前
0

It seems it wont work

已回答 5 年前
0

Moved to other post

已回答 5 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则