Stéphane
Stéphane

Reputation: 1789

Is it possible to retrieve topic name inside a Lambda function called by an Iot rule

I've got a lambda function called by an IoT rule and I would like to know the topic name from inside this lambda function.

So far i'm only able to retrieve the message data from the event parameter. Nothing in the context parameter neither.

I haven't found anything in the documentation...

Is it even possible ?

Upvotes: 3

Views: 1054

Answers (1)

Andrey Prokopiev
Andrey Prokopiev

Reputation: 841

You need to use topic() function in AWS IoT SQL query. Like this:

SELECT * as data, topic() as topic FROM 'desired/+/topic'

In this case, your event will include the original message in 'data' field and the used topic in 'topic' field. You can also use integer number as a parameter inside topic() function, to return only sub-group.

More data in oficial documentation: http://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-function-topic

Upvotes: 8

Related Questions