AWS Amplify PubSub: "Malformed UTF data" error when getting compressed binary data?

81 views Asked by At

I am working on a react project that uses AWS Amplify Authentication and PubSub.

The user signs in using a custom provider, and subscribes a topic based on their cognito-identity-id.

I am able to successfully sign in and subscribe to topics.

The data that is published to it is compressed binary data

...
const { gzip } = require('node-gzip')
payload = await gzip(data)
...

When I receive this data, I get the following warning in ConsoleLogger.js

[WARN] 50:28.664 MqttOverWSProvider  {
  "errorCode": 5,
  "errorMessage": "AMQJS0005E Internal error. Error Message: AMQJS0009E Malformed UTF data:8b -78 ., Stack trace: No Error Stack Available",
  "uri": "..."
}

The connectionState then goes to ConnectionDisrupted and it reconnects.

I don't have this issue when I publish a regular JSON object to the topic.

Code snippet:

Amplify.configure(awsExports)
Amplify.addPluggable(
  new AWSIoTProvider({
    aws_pubsub_endpoint: `wss://${awsExports.PubSub.endpoint}/mqtt`,
    aws_pubsub_region: awsExports.PubSub.region,
  })
)
...
PubSub.subscribe(`test/${signedInUserId}/companies`).subscribe({
    next:data=>console.log('got data')
  })

My plan is to get the binary data and use Pako.inflate() to convert it to JSON, but I can't get that far because it throws that warning/error before the next() is called.

Why am I getting this error when I receive binary data, and how do I get PubSub to accept compressed binary data?

Thank you.

0

There are 0 answers