Install AWS IoT Greengrass on Ubuntu

Introduction

Since I learned about AWS IoT Greengrass in my company's business, I would like to introduce Ubuntu-equipped devices and applications using AWS IoT in several parts from this time. For the first time, we will show you how to create a Greengrass Group on the cloud and how to install Greengrass Core on edge devices.

There is also Article using Azure IoT Edge, so please have a look if you are interested.

environment

Operation confirmed device (OS)

These devices work with packages of the armhf architecture. I also operate the device on a PC running Windows 10.

What is AWS IoT Greengrass?

AWS IoT Greengrass is software for edge computing provided by AWS. By installing Greengrass on your edge device, you can easily connect to the cloud and deploy applications from the cloud. In addition, by extending some functions of the cloud to edge devices, it is possible to collect and analyze data near the data source, take action on local events, communicate between local devices, and so on. For details, please see AWS IoT Greengrass Official Site.

Preparation

Creating an AWS account

If you don't have an AWS account, create one. https://aws.amazon.com/jp/ There is also a limited free tier. The AWS IoT free usage tier used this time is [here](https://aws.amazon.com/jp/free/?nc2=h_ql_pr_ft&all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier You can check it with .sort-order = asc & awsf.Free% 20Tier% 20Categories = categories% 23iot).

WinSCP installation

Install WinSCP on your PC to transfer files from your PC to your device. Please see the official website for installation and usage. https://winscp.net/eng/index.php

Install Python 3.8

Install Python 3.8 for use with Greengrass Lambda.

sudo apt update
sudo apt install python3.8

Confirm the installation is successful.

username@ubuntu:~$ python3.8 --version
Python 3.8.0

Java 8 installation

Install Java 8 for use with Greengrass Stream Manager.

sudo apt update
sudo apt install openjdk-8-jdk

Link to the installed Java.

sudo ln /etc/alternatives/java /usr/bin/java8

Confirm the installation is successful.

username@ubuntu:~$ java8 -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~18.04-b01)
OpenJDK Client VM (build 25.275-b01, mixed mode)

cgroup enablement

Enable cgroup to run Lambda in the container.

Open /boot/firmware/cmdline.txt.

sudo vi /boot/firmware/cmdline.txt

__ Add the following values to the end of the existing line.

cgroup_enable=memory cgroup_memory=1

Reboot the device.

sudo reboot

Creating a Greengrass Group

Follow the steps in the official AWS guide [^ ggconfig] to create a Greengrass Group in the AWS Management Console.

  1. Select the Tokyo region from the menu on the top right. gg0.png

  2. Open the "Services" menu in the upper left, enter "iot greengrass" in the search window, and click "IoT Greengrass". gg1.png

  3. From the left navigation pane, go to Greengrass → Introduction and click Create Group. gg2.png

  4. Click Use Default Creation.

  5. Name the group and click Next. This time, let's call it "eRT3 Group".

  6. Specify the name of the Greengrass Core. Keep the defaults and click Next.

  7. A confirmation screen will be displayed. Confirm and click "Create Group and Core".

  8. Click Download these resources as tar.gz to download the security resources to connect your device to the cloud. This file cannot be downloaded later, so be sure to download it here. After downloading, click "Finish" to complete the settings.

Installing Greengrass Core on your device

Install and launch the Greengrass Core software on your device. There are multiple ways to install the Greengrass Core software, but here we will install it from the APT repository [^ apt].

Setting up security resources and root CA certificates

Set up the security resources and root CA certificate needed to connect the device to the cloud.

Security resource installation

  1. Launch WinSCP, connect to the device, and place the security resource (tar.gz file) downloaded in step 8 of Creating a Greengrass Group (creating a #greengrass-group) in your home directory. gg8-2.png

  2. Run the following command to install the security resource. Replace <hash> with the file name of the security resource.

    sudo mkdir -p /greengrass
    sudo tar -xzvf ~/<hash>-setup.tar.gz -C /greengrass
    

Download root CA certificate

  1. Go to / greengrass / certs.

    cd /greengrass/certs/
    
  2. Download the Amazon Root CA 1 certificate with the name root.ca.pem.

    sudo wget -O root.ca.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
    

Make sure the downloaded root.ca.pem is not empty (downloaded correctly). If the file is empty, please try the download again.

```bash
cat root.ca.pem
```

Install Greengrass Core software

  1. Create a Greengrass system account.

    sudo adduser --system ggc_user
    sudo addgroup --system ggc_group
    
  2. Install the AWS IoT Greengrass keyring package and add the repository.

    cd ~
    sudo wget -O aws-iot-greengrass-keyring.deb https://d1onfpft10uf5o.cloudfront.net/greengrass-apt/downloads/aws-iot-greengrass-keyring.deb
    sudo dpkg -i aws-iot-greengrass-keyring.deb
    
    username@ubuntu:~$ echo "deb https://dnw9lb6lzp2d8.cloudfront.net stable main" | sudo tee /etc/apt/sources.list.d/greengrass.list
    deb https://dnw9lb6lzp2d8.cloudfront.net stable main
    
  3. Update the list of packages and install the Greengrass Core software.

    sudo apt update
    sudo apt install aws-iot-greengrass-core
    
  4. Start the Greengrass daemon.

    sudo systemctl start greengrass.service
    

Execute the following command, and if the displayed Active status isactive (running), the daemon is operating normally.

```bash

username@ubuntu:~$ systemctl status greengrass.service

Execute the following command to start automatically when the device starts.

```bash
sudo systemctl enable greengrass.service
```

Operation check

Make an empty deployment to see if your device can connect to the cloud.

  1. From the menu on the left, go to "Groups" and click on the group you created. gg11-a.png

  2. Click Deploy from the Actions menu to start the deployment. gg9.png

  3. Click Auto Detect. gg28.png

  4. Wait a few minutes for the deployment to complete. If the deployment completes successfully, it is successful. gg10.png

Summary

We created a Greengrass Group in the cloud and installed Greengrass Core on our device. Stay tuned for next time we'll be creating and deploying Lambda!

Supplement

proxy settings

If the device is in a proxy environment, proxy settings are required. The settings differ depending on the environment, but for reference, I will introduce the settings I made this time.

Setting environment variables

Please see this article.

Greengrass Core settings

Set up Greengrass Core according to the official AWS document [^ proxy].

  1. If Greengrass is running, stop it.

sudo systemctl stop greengrass.service ``` 2. Add write permission to /greengrass/config/config.json and open it.

```bash

sudo chmod +w /greengrass/config/config.json sudo vi /greengrass/config/config.json ``` Add the iotMqttPort and networkProxy objects inside the coreThing object. The file after adding is as follows.

```/greengrass/config/config.json

{ "coreThing" : { "caPath" : "root.ca.pem", "certPath" : "3283c6f04d.cert.pem", "keyPath" : "3283c6f04d.private.key", "thingArn" : "arn:aws:iot:ap-northeast-1:xxxxxxxxxxxx:thing/eRT3Group_Core", "iotHost" : "xxxxxxxxxxxx-ats.iot.ap-northeast-1.amazonaws.com", "iotMqttPort" : 443, "ggHost" : "greengrass-ats.iot.ap-northeast-1.amazonaws.com", "keepAlive" : 600, "networkProxy":{ "proxy":{ "url" : "http://username:[email protected]:port/" } } }, ... ``` 3. Remove write permissions from the file and restart Greengrass.

```bash

sudo chmod -w /greengrass/config/config.json sudo systemctl start greengrass.service ```

reference

[^ ert3]: [Real-time OS controller e-RT3 Plus F3RP70-2L](https://www.yokogawa.co.jp/solutions/products-platforms/control-system/real-time-os-controller/ert3- ai-platform /)

Recommended Posts

Install AWS IoT Greengrass on Ubuntu
Install pyqt5 on ubuntu
Install Ruby on Ubuntu 20.04
Install Autoware on Ubuntu 18.04.5
Install Homebrew on Ubuntu 20.04
Install OpenJDK7 (JAVA) on ubuntu 14.04
Install Cybozu Office 10 on Ubuntu 20.4
Install Docker on Ubuntu Server 20.04
AWS CLI install in Ubuntu 20.04
Install zabbix agent (5.0) on Ubuntu 18.04
Install MAV Proxy on Ubuntu 18.04
Install Arudino IDE on Ubuntu 20
Install Java on WSL Ubuntu 18.04
Install Ubuntu Desktop 20.10 on RaspberryPi4
Install Arduino IDE on Ubuntu 20.04
Install raspi-config on Ubuntu 20.04 (LTS)
Install docker on AWS EC2
Install WordPress 5.5 on Ubuntu 20.04 LTS
Install PlantUML on Intellij on Ubuntu
Install Ubuntu Server 20.04 on Btrfs
Note: Install PostgreSQL 9.5 on Ubuntu 18.04
Install Docker on AWS Ubunt 20.04 LTS
Using Azure IOT Hub on Ubuntu 20.10.
Install JDK and JRE on Ubuntu 16.10
Install ngrok on ubuntu16.04 using Vagrant
How to install WildFly on Ubuntu 18.04
Install MQTT broker Mosquitto on Ubuntu 18.04
I tried running a Docker container on AWS IoT Greengrass 2.0
Install SonarQube on ECS instance on Ubuntu 16.04
Install ruby on Ubuntu 20.04 with rbenv
EFS mount on AWS Ubuntu EC2 (amazon-efs-utils)
Headless install of Ubuntu 20.10 on Raspberry Pi
Install OpenJDK (Java) on the latest Ubuntu
How to install production Metabase on Ubuntu
I want to install PHP 7.2 on Ubuntu 20.04.
Install Realtek network driver on Ubuntu Note
ubuntu (AWS) LEMP
tmux on Ubuntu
Wine settings on Ubuntu 18.04 (install WOLF RPG Editor)
Build and install Wireshark Development Release (3.3.1) on Ubuntu
Install Ubuntu Core 18 on Raspberry Pi 2 Model B
How to install network drivers on standalone Ubuntu
How to install NVIDIA driver on Ubuntu 18.04 (Note)
How to install multiple JDKs on Ubuntu 18.04 LTS
Install and switch between multiple Javas on Ubuntu
Install the latest version of Jenkins on Ubuntu 16
Screen recording on Ubuntu 20.04
Install gradle on mac
Install docker-compose on a Graviton 2 instance of AWS EC2
How to install Ruby on an EC2 instance on AWS
Install Corretto 8 on Windows
Install OpenJDK on macOS
Try DisplayLink on Ubuntu 20.04
Reinstall Kubernetes on Ubuntu 19.10
Install Java on Mac
Install Golang on CentOS 8
Install Oracle JDK 8 via PPA in AWS Ubuntu Server 16.04
Use Flutter on Ubuntu
Install Neo4j 4.1.3 on centOS
Install ROS Noetic ubuntu20.04
[CentOS7] Install aws cli