amazon-web-servicesaws-iot

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?


Solution

  • 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.