aws iot rule sql

0

AWS IoT Rule Engine can handle MQTT Payload values ​​through SQL statements. When MQTT Client sends a message by putting a byte array value in the payload, can the byte array value be decoded and selected through SQL statements? For example,

Publish

  • topic : test/payload
  • payload : [72,101,108,108,111,119,111,114,108,100] (( Hello World )) SQL SQL SELECT * FROM 'test/payload' I wonder if it is possible to SELECT 'Hello World' by converting the above payload.
已提问 1 年前423 查看次数
2 回答
0

Hi,

there are no native functions in the SQL supported by Rules engine to decode binary data, but you can pass the data to a Lambda function that can return the decoded payload. Since Lambda functions do not support binary input, you need to convert the input to base64.

SELECT aws_lambda("arn:aws:lambda:us-east-1:account_id:function:lambda_function", {"message":encode(*, 'base64'}) as output FROM 'test/payload'
AWS
专家
已回答 1 年前
0

Hi rePost-User-1228067,

Thanks for your question! If I understand correctly:

  • You have a Byte array as your MQTT payload
  • You are trying to perform a filter on the decoded content from the binary array to know if the decoded (plain text) equals 'Hello World' for example. Then sending it out to some downstream services. Is that correct?

If that's the case, then your answer is yes (provided that your binary data is Base64 or Protobuf encoded). The native function is 'decode' and the syntax is decode(value, decodingScheme) where 'value' is the encoded string payload and decodingScheme is either 'base64' or 'proto'.

In your specific example, depending on the client flexibility, you'll either ensure first that your payload is a Base64 binary (or Protobuf) encoded value instead of a Byte Array, or have a lambda function cloud side to transform Byte Array to Base64 binary and republish to a new topic for processing. Then do the following:

SELECT decode(payload,"base64") AS myfilterresult from 'test/payload' where decode(payload,"base64") = 'Hello World' ; or anything similar, depending on the filtering conditions you'd like to apply.

Here are some documentation links for reference:

https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-sql-decode-base64.

https://docs.aws.amazon.com/iot/latest/developerguide/binary-payloads.html

profile pictureAWS
专家
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则