Now that we’ve given you a general overview of how AWS IoT Greengrass itself is put together, we will walk through options for connecting IoT devices such as sensors and cameras as things behind the Greengrass Core device.
Local MQTT broker and the MQTT bridge
IoT devices can send MQTT messages directly to AWS IoT Core in the cloud via the public endpoints in the nearest AWS region. However, if they prefer to relay messages via a Greengrass Core device, they need to target an MQTT broker running locally on it. Two public components can be pushed out to a Greengrass Core device for this purpose. One is based on Moquette (for MQTT v3.1.1) and the other is EMQX (for MQTT v5). Regardless of which the customer chooses, by default, when a device sends MQTT messages to the local broker, they will just sit there doing nothing unless another component grabs them and acts:
Figure 9.11 – An MQTT broker relaying messages to AWS IoT Core via the MQTT bridge component
The preceding figure gives an overview of how the MQTT bridge can be inserted to relay these messages to matching topics in the AWS region. In the Greengrass deployment, the MQTT bridge component is added and configured to listen to specific topics on the local MQTT broker. It will automatically pick them up and insert them into matching topics in AWS IoT Core:
Figure 9.12 – MQTT bridge component configuration example
Take a look at the preceding configuration example. The “topic” parameter is set to listen to whatever local MQTT broker is running for topics matching a certain pattern. The “target” parameter tells it where to replicate them to.
This is a simple example of how an AWS IoT Greengrass Core device can aggregate MQTT messages, regardless of the connectivity status back to the AWS region. Greengrass will keep trying to talk to whatever endpoint in AWS it is configured for until the path comes up, at which time any messages the bridge has picked up will be pushed to AWS IoT Core. If the uplink is down for a week, the bridge will keep buffering messages in this way – so long as it has sufficient local resources to store them.