Connecting a device to Greengrass Core

The steps required to connect an IoT device with AWS Greengrass are very similar to those we performed during the setup of the AWS IoT Core. In this section, we are going to extend our dummy IoT device (Ubuntu Server on a virtual machine) with Greengrass using the AWS Management Console:

  1. To get started, from the AWS IoT console, select the Greengrass option from the navigation pane.
  2. Setting up Greengrass involves a three-step process starting with creating and configuring a Greengrass group, followed by adding a Greengrass Core to the group and finally, by adding the IoT device to the group. To get going, click on the Get Started option under the Define a Greengrass Group tile.
  3. On the Set up your Greengrass Group page, select the Use easy creation option. This process will automatically provision a Core in the registry, use default settings to generate a new group, and provide your core with a new certificate and a key pair.
  4. Type in a suitable group Name for the Greengrass group and click on Next to proceed.
  5. You can optionally choose to apply a type to this group by selecting the Thing Type from the drop-down box, as shown in the following screenshot. In this case, we already have a Thing Type defined from our previous exercises so we are going to use this. Click on Next to continue:
  1. Since we are using the easy creation method, AWS runs a scripted action that basically performs the following set of tasks for us:
    • Create a new Greengrass group in the cloud
    • Provision a new core in the IoT registry and add to the group
    • Generate a public and private key set for your core
    • Generate a new security certificate for the core using the keys
    • Attach a default security policy to the certificate
  2. Click on Create Group and Core to proceed with the scripted install.
  3. Finally, on the Connect your Core device page, download the core-specific certificates and config file as a TAR resource by selecting the Download these resources as a tar.gz option. You will also need to download an appropriate version of the Greengrass Core software to run on your IoT device. Since we are performing all of these activities on a Ubuntu-based virtual machine, select the x86_64_Ubuntu option from the Greengrass Core software drop-down list and download it. Once done, click Finish to exit the setup.

With both the Greengrass Core software and the necessary Greengrass certificates downloaded, we now have to transfer them to our IoT device using any SCP tool. Once transferred, run the following set of commands to set up and start the Greengrass Core:

  1. First up, untar the Greengrass Core software using the following command.
# sudo tar -xzvf greengrass-<PLATFORM-VERSION>.tar.gz -C /
  1. Next, run the following command to untar and place the security files and certificates in the greengrass directory:
# sudo tar -xzvf <UID>-setup.tar.gz -C /greengrass
  1. Once the contents of both the TAR files are extracted, run the following command to download the Root CA certificate from Symantec:
# cd /greengrass/certs/
# sudo wget -O root.ca.pem http://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem

Here is the final folder structure for your reference:

  1. Once completed, run the following set of commands to create a dedicated user and group for Greengrass Core software:
# sudo adduser --system ggc_user 
# sudo addgroup --system ggc_group 
  1. Next, update the host operating system and install a sqlite3 package on it using the following commands:
# sudo apt-get update 
# sudo apt-get install sqlite3 
  1. With all the pieces of the puzzle in place, we are now ready to finally start the Greengrass Core service on our IoT device. Type in the following command as shown:
# cd /greengrass/ggc/packages/1.3.0/ 
# sudo ./greengrassd start

You should get the following output on your Terminal, as shown in the following screenshot:

In case of errors in connecting, you can also check the Greengrass runtime log file at the following location:

/greengrass/ggc/var/log/system/runtime.log.

Simple, isn't it! With two out of three steps completed, the final step left in completing the Greengrass connectivity is adding a device to the Greengrass group that we have created:

  1. To do so, from the AWS IoT console, select the Groups option provided under the Greengrass section from the navigation pane. You should see your newly created Greengrass group present here. Select it.
  2. Select Devices and click on the Add your first Device option to continue.
  3. Here in the Add a Device page, you can opt to either Create a new Device or optionally Use an existing IoT Thing as an Device. Since we already have the IoT device registered from our earlier IoT setup, select the Select an IoT Thing option to proceed.
  4. Select the name of the added IoT device and click on Finish to complete the process.

There you have it! You have successfully installed and connected your IoT device with AWS Greengrass! In the next section, we will test this deployment by running a simple Lambda function on it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset