3

I have configured a lambda to a IOT Rule. The MQTT topic will get binary data and on arrival of data the rule should invoke lambda.

The lambda gets invoked when I post normal JSON data, but if I post any binary data, the lambda does not get invoked.

But at the same time, I am able to consume the binary data posted to MQTT through my stand alone consumer and able to deserialise it successfully.

So what is that I am missing here ?

1 Answer 1

4

When the message payload should be handled as raw binary data (rather than a JSON object), you can use the * operator to refer to it in a SELECT clause.

Do this on your rule:

SELECT encode(*, 'base64') AS data, timestamp() AS ts FROM 'a/b'

This way it will get invoked.

https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-select.html

Sign up to request clarification or add additional context in comments.

4 Comments

I was previously using SELECT * from 'a/b', looks like even this query should have invoked the lambda as per documentation. I will give a try with the rule suggested by you.
As a follow-up for anyone who can't this working, the following SELECT timestamp() AS ts, encode(*, 'base64') AS data FROM 'a/b' - does not work but.. SELECT encode(*, 'base64') AS data, timestamp() AS ts FROM 'a/b' - does. The base64 statement must come first.
My data is already base64 encoded, this causes it to be double encoded. If it possible to receive raw base64 days without double encoding?
I am also trying the same thing. AWS lambda function should invoke when AWS IoT receives payload in binary. How does SELECT encode(*, 'base64') AS data, timestamp() AS ts FROM 'a/b' query trigger lambda function without calling AWS IoT core SQL aws_lambda function?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.