AWS IoT MQTT over WebSocket Protocol
Asked Answered
H

2

15

I've been following the AWS IoT docs trying to get started with the MQTT tutorial at http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html#mqtt-ws to set up a WebSocket connection to AWS IoT in a web application. The first step is to initiate a WebSocket connection by making a GET request to an endpoint created by following the steps in the tutorial but I'm getting this error:

XMLHttpRequest cannot load <my endpoint> Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

I was wondering if anyone has encountered this error and if so, how they resolved it?

Here's a link to the code https://github.com/dwyl/learn-aws-iot/blob/2c8035728ec8228e296580c8714f3f7ace870fbe/src/js/components/App.js

Hewe answered 11/2, 2016 at 16:59 Comment(2)
Is the failing GET request to the describe-endpoint API or to open the WebSocket? If trying to open the WebSocket, are you using a Javascript client which supports WebSockets or making a normal HTTP request to the endpoint?Rufford
I'm making a normal HTTP request through XMLHttpRequest to open the websocket using a url of the form wss://<endpoint>.iot.<region>.amazonaws.com/mqtt which has been signed using the amazon signature version 4Hewe
S
7

Here's an example of how I'm opening the channel. I'm using Cognito unauth roles as a subscriber. I'm using the JS Paho client as well.

http://draw.kyleroche.com/main.js

Sitdown answered 11/2, 2016 at 19:42 Comment(4)
Thanks! Can you share your SigV4Utils.getSignedUrl function?Bluestone
Yeah it would be great if you could share this utils function. Can't seem to find it anywhere in the docsHewe
See here for the utility function being used.Izabel
More info in the docs.Izabel
R
4

AWS Labs has also posted an MQTT over WebSockets reference example here: https://github.com/awslabs/aws-iot-examples

Rufford answered 12/2, 2016 at 17:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.