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.
질문됨 일 년 전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
전문가
답변함 일 년 전
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
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인