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년 전433회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠