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?

posta 5 anni fa433 visualizzazioni
6 Risposte
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
con risposta 5 anni fa
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'
con risposta 5 anni fa
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
con risposta 5 anni fa
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

con risposta 5 anni fa
0

It seems it wont work

con risposta 5 anni fa
0

Moved to other post

con risposta 5 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande