AWS IOT: Does the platform act as an MQTT broker? - amazon-web-services

I just need to be sure whether I would need to use a separate library/provider such as Mosquitto and HiveMQ and integrate them with AWS IOT or would the amazon platform act as a self sufficient endtoend solution.
TIA

The AWS IoT service includes an MQTT message broker.

I am not into AWS IoT that deep, but:
When using a MQTT Broker, make sure that
* each device gets individual credentials
* device cannot subscribe to topics of other devices (unless that is explicitly what you want).
BR,

Related

Google IoT Core - How to subscribe to a topic

I have developed a device that is able to connect to Google IoT Core through the MQTT protocol, I can publish MQTT messages on telemetry topics (/devices/DEVICE_ID/events).
But I can't figure out how to subscribe my device to a generic topic and send messages from cloud to device via this topic.
Through the console I created the topic MyTestTopic and a subscription MyTestTopic-sub, I guess that somehow I have to subscribe my device to the subscription MyTestTopic-sub, but I don't know to which topic I have to subscribe my device.
I tried to subscribe my device to the following topics:
projects/PROJECT_ID/topics/MyTestTopic
projects/PROJECT_ID/topics/MyTestTopic-sub
/devices/DEVICE_ID/events/MyTestTopic
/devices/DEVICE_ID/events/MyTestTopic-sub
the subscription to these topics seems to be successful, but the device does not receive the messages I send from the console.
Any suggestions please?
I found this thread (Google Cloud IoT - Invalid MQTT publish topic) from 4 years ago, from which I understand that it is possible to subscribe only to some predefined topics, also from the various documents I have read I understand that Google IoT Core allows devices to subscribe to only two topics: /devices/{device-id}/config and /devices/{device-id}/commands/#
Has anything changed since then?
So to be clear, there are two different "topics" in play here. There's the MQTT topics that are described in the docs you found, config and commands. Those are subscribed to on the device using an MQTT client (e.g. Paho MQTT), and sent down to the device from somewhere else via the IoT Core Admin APIs. Then there's Pub/Sub topics. Out of the box, a device using IoT Core does not directly interact with Pub/Sub at all. They publish/receive via the MQTT topics only. So if you register a device with IoT Core, all messages come and go via the MQTT bridge (or HTTPS).
What Gambit support linked to in that github repo is a direct subscription to a Pub/Sub topic (not MQTT). If you look at the Python code, it's establishing proper Google Cloud Credentials via a json token (service account bearer token) that needs to be present on the device or a proxy device. Depending on the device you're using, that may not be possible of course (implementing GCP APIs on a microcontroller is difficult at best).
The easiest way I've seen this done is to implement a Cloud Function that subscribes to a Pub/Sub topic you want to use, and it implements the proper IoT Core Admin calls to push the Pub/Sub messages down to the device as needed. But of course, it all depends on what you're trying to do.

Google Cloud IoT- How to publish to the same topic with multiple IoT devices and process it by cloud functions

In my project multiple IoT devices need to publish to a single topic and cloud functions listening to that topic need to process data published by IoT devices. Multiple devices should be able to publish at the same time.A MQTT broker logic is needed. But in Google IoT Core "The MQTT bridge allows only a single connection for a given device ID. If a second device connects with the ID of a device that is already connected, the older device connection will be closed automatically.".
I am new to google cloud IoT and trying to understand basic concepts. I have looked into gateways but I am not sure that gateways work as broker. Can multiple devices publish through a gateway to a same single topic? or should I implement/add a MQTT broker(mosquitto I guess) myself or is there an another way to use google Cloud IoT in my case? Could you guys direct me to the right direction. Opening sub/pub topics for each device doesn't sound right because in my project there can be thousands of IoT devices.
Let all the devices in the registry publish messages to the common topic given to the registry.Then trigger a cloud function with this topic.
You can process the messages with cloud function based on the deviceId

Does using a custom authorizer with aws-iot (wss) create a new device everytime a device connects and sends data?

Considering there are a bunch of mobile devices (Android and iOS) that need to be sending data to AWS-IoT via MQTT custom authorizer to check for valid token based on business logic is to be implemented.
Referring to IoT Apps with AWS IoT and Websockets, slide 56/60 shows the registration process where a lambda is used to create and attach a policy.
Does this indicate that the lambda will create a new AWS-IoT device and attach the policy to that device? Which results in creating a new AWS-IoT device everytime a new user signs up?
Referring to How to Use Your Own Identity and Access Management Systems to Control Access to AWS IoT Resources
, you can create your custom-authorizer. Once that's done, you can use aws/aws-iot-device-sdk-js to test out the authorizer by using this piece of code.
Using custom authorizer doesn't require you to create or have any
things registered in your account.
You are billed for your connections, messages etc as per AWS's IoT pricing.
However this is a mqtt over wss implementation and not a mqtt only implementation. As of now, the mqtt only implementation still seems to require certificates during connection to the AWS-IoT broker.
To expand on user2967920's answer:
You do not need to create devices when using AWS IoT Core. AWS Amplify PubSub actually uses IoT as a general-purpose MQTT broker. No devices will be created by using a custom authorizer*.
The policy returned by your custom authorizer is not persisted. Think of it as a dynamic, ad-hoc policy created for a specific connection.
For an example of using AWS IoT on Android and iOS, check out the documentation of AWS Amplify PubSub (which uses AWS IoT Core internally). On iOS:
iotDataManager.connectUsingWebSocket(withClientId: uuid,
cleanSession: true,
customAuthorizerName: "<name-of-the-custom-authorizer>",
tokenKeyName: "<key-name-for-the-token>",
tokenValue: "<token>",
tokenSignature: "<signature-of-the-token>",
statusCallback: mqttEventCallback)
*Obviously you can create devices in the lambda function if you choose to, just like you can use any other AWS API.

How to distribute reads of an MQTT topic from AWS Iot over multiple consumers?

I'm using AWS IoT to get device logs from multiple moving devices. Currently, all devices can publish their status to the AWS IoT Core using MQTT. Now I'd like to create an application service from outside AWS (servers are in my company) that will subscribe and consume device status from AWS IoT. I'm facing the issue like that, the app backend can get data from AWS IoT. However, it cannot be distributed or load balanced. Just the last connected consumer can get the data. How can I distribute/scale the reads from AWS IoT or any alternative/suggested solutions?
Thanks in advance!

How to publish message from AWS IoT to another host?

I would like to publish message from Amazon IoT to another host. In Amazon IoT there is MQTT client which have publish and subscribe functionalities. But as far as I know of MQTT client it can publish and subscribe with in Amazon only. I also checked aws iot commands. They don't provide commands for publish and subscribe. Can anyone suggest a way to publish messages from Amazon IoT to another host?