How to create a local IoT broker with greengrass and connect it to the aws cloud

Eduard Schwarzkopf
22. September 2023
Reading time: 0 min
How to create a local IoT broker with greengrass and connect it to the aws cloud
 class=

Introduction

Greengrass is a software developed by Amazon Web Services (AWS) for the deployment of local compute, messaging, and data caching capabilities for Internet of Things (IoT) devices. This allows IoT devices to operate even when disconnected from the cloud and enables real-time local processing and the ability to respond quickly to events.
One common deployment scenario for Greengrass is using a small, low-power IoT device as the core device. These devices, such as the Raspberry Pi, can be configured to run Greengrass and connected to sensors and actuators. This allows for data to be collected and processed locally on the IoT device, and then securely sent to the cloud for further analysis and storage. This approach can be particularly useful in situations where a reliable internet connection may not be available or where low latency is crucial. In situations where more CPU power is needed, a more powerful device can be used as the IoT core. For example, a larger single-board computer like the NUC or Intel’s IoT gateway could be used, providing more processing power and storage capacity for more demanding workloads. Additionally, the ability to run AWS Lambda functions on the IoT device with Greengrass enables the execution of specific business logic on the device itself, reducing the need to constantly send data to the cloud.

Prerequisites

Disclaimer: This tutorial is for people that know the basics of AWS and can read code.

What you need to follow this tutorial:

Hardware

  • Raspberry Pi (Recommended is a Pi 3 or 4. For setting up a Zero, check out this video)
  • SD Card
  • Electricity (Duh!)

Software

  1. AWS IoT Greengrass Core software: This is the software that runs on the Raspberry Pi and provides local compute and communication capabilities for connected devices. It can be downloaded from the AWS IoT Greengrass website.
  2. Operating System: Greengrass v2 supports Linux or Windows. In this tutorial, I’m going to use Raspberry Pi OS.
  3. Python: Greengrass uses python as its primary programming language. It requires python 3.7 or higher.
  4. pip
  5. virtualenv

Also, grab a cup of coffee, you’ll need it. Go ahaid, I’ll wait for you.

 class=

Local Setup

There are plenty of tutorials on how to set up a Raspberry Pi, so I won’t go through this topic. If you need a tutorial, please read the official documentation, most tutorials are outdated on how to set up a pi:
https://www.RaspberryPi.com/documentation/computers/getting-started.html
Just make sure, it has SSH and access to the internet.

SSH onto your Raspberry and install the following software.

But first, let’s update our raspberry:

sudo apt update && sudo apt upgrade -y

Install Java:

sudo apt install default-jdk

check if Java is installed with:

java --version

you should get a version from this command, like this:

openjdk 11.0.16 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Raspbian-1deb11u1)
OpenJDK Server VM (build 11.0.16+8-post-Raspbian-1deb11u1, mixed mode)

Cloud Setup

Go to the AWS Management Console and head over to IAM. We need a User. Give that User programmatic access and make sure to save the Access and Private Key.
You’ll need the user just to pull the correct data during the Greengrass installation. When that is done, you can delete that user.

 class=

Again: it is important to grab the access and secret key, after creating the user.

Now that user needs the right permissions. Create a Policy with the following permissions:

{
    "Version": "2012-10-17",