Hashan Seneviratne
Hashan Seneviratne

Reputation: 1177

Handling string payloads from AWS IOT Rule

My thing would publish string payload something like "[v1:ThingName]" to a topic (someTopic/topic1). And I have a rule applied in the rule engine to capture this topic and send to a Lambda function.

SELECT * FROM 'someTopic/+'

I want to send the topic1 part which will be captured from Rule engine along with the payload. So it can be captured from topic(2). How do I concatenate topic(2) with * in select statement?

Upvotes: 0

Views: 932

Answers (2)

epietrowicz
epietrowicz

Reputation: 384

I'd add one answer for an already encoded base64 string from your "Thing".

In my example, the message contained an encoded base64 image from the ESP32-CAM. I was able to get my lambda function to trigger and have the correct encoding with the following rule:

SELECT decode(encode(*, 'base64'), 'base64') as base64Image

Recommended from the AWS docs.

Upvotes: 0

Hashan Seneviratne
Hashan Seneviratne

Reputation: 1177

After so much of trial and error, figured that you cannot do it like that because payload is string.

But how I got away with this was using the encode function. Essentially I encode the whole payload into base64 as a json object and then have the topic(2) value as well.

So my Rule SQL query would like this.

SELECT encode(*, 'base64') as encode, topic(2) as topic FROM 'someTopic/+'

Subsequently you decode the payload in the Lambda function.

Upvotes: 2

Related Questions