Connecting a device to AWS IoT Core

AWS IoT supports a wide variety of specialized IoT-embedded devices and microcontrollers that you can connect to. However, for simplicity, you can also simulate an IoT device using either a locally set up virtual machine or an EC2 instance, as well. For this section, we will be using a simple Ubuntu-based virtual machine, hosted using VirtualBox. The virtual machine has the basic operating system packages installed in it and runs off a 512 MB RAM and 1 CPU core allocation with a 10 GB disk. Ensure that your virtual machine has an open internet connectivity and a valid hostname set, before you proceed with any further steps.

The following list demonstrates the simulated IoT device's configuration for your reference:

  • CPU: 1 CPU
  • RAM: 512 MB
  • Operating System: Ubuntu Server 16.04.2 LTS (Xenial) x86_64 architecture
  • Packages: Core server packages along with vim, node, npm, git, wget

Once the device or virtual machine is prepped, we are good to connect with the AWS IoT Core:

  1. From the AWS Management Console, filter and select the AWS IoT service using the Filter provided. Alternatively, select this URL, https://console.aws.amazon.com/iot/home to launch the AWS IoT console.
  2. Select the Get started option to continue.
  3. Once logged into the console, select the Onboard option from the navigation pane on the left-hand side of the console. Here, you can opt to get started with configuring your first device with the IoT service as well as other options, such as configuring the AWS IoT Button or getting started with the AWS IoT Starter Kit. For this section, select the Get started option under the Configure a device section.
  4. The Get started option is a simple three-step process that involves first registering your device, followed by downloading a set of credentials and SDKs for the device to communicate with the IoT Core, and finally testing to check whether the device is successfully connected or not.
  5. Select Linux/OSX from the Choose a platform option followed by Node.js from the Choose a AWS IoT Device SDK, as shown in the following screenshot. Note here, you can alternatively select the Java or Python SDKs as well; however, the rest of this particular use case will be based only upon Node.js:
  1. Once the appropriate platform and IoT SDK are selected, click on Next to continue.
  2. The next step involves the registration of a thing or in our case, the IoT device itself. Start off by providing a suitable Name for your thing and then select the Show optional configuration option.
  3. In the Apply a type to this thing section, select the Create type option. A Thing Type simplifies managing IoT devices by providing a consistent registry data for things that share a particular type. Provide a suitable Name and an optional Description for your Thing Type and select Create thing type when done.
  4. Here's what the final configuration should look like. In my case, I've created a Thing Type called dummyIoTDevice for logically classifying all virtual machine-based IoT devices together. Select the Create Thing option once completed:
  1. With the thing successfully created, we now need to establish the connection between the thing and AWS IoT Core. To do so, select the newly created thing tile from the Things console to view the thing's various configurations. Among the important options is the Security option. Go ahead and select the Security option from the navigation pane.
  2. Here, you can create and associate the necessary certificates, as well as policies that will be required for Thing to communicate with the IoT Core. Select the Create certificate option to begin with.
  1. The necessary certificates are created automatically by AWS Core. Download these files and save them in a safe place. Certificates can be retrieved at any time, but the private and public keys cannot be retrieved after you close this page:
    • A certificate for this thing: xyz.cert.pem
    • A public key: xyz.public.key
    • A private key: xyz.private.key

In addition, you will need to download the root CA for AWS IoT from Symantec. You can do that by selecting the following URL:

https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem

Remember to select the Activate option to successfully activate the keys. Once done, select the Attach a policy option, as shown in the following screenshot:

  1. Since this is our first time working with the IoT Core, we will be required to create a new policy from scratch. The policy will be used to authorize the certificates we created in the previous step. Select the Create new policy option to get started.
  2. In the Create a Policy page, start by providing a suitable Name for your new policy. Once completed, you can use either the basic or advanced mode to create your IoT policy. For simplicity, select the Advanced mode option and paste the following policy snippet as shown:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "*"
}
]
}

The following policy grants all devices permission to connect, publish, and subscribe to the AWS IoT message broker. You can alternatively tweak this policy as per your requirements, as well.

  1. Once done, select the Create option to complete the policy creation process.

With this step completed, we are but a few steps away from establishing the connection between our IoT device and the AWS IoT Core.

  1. With the necessary policy created and the certificates downloaded, we now need to copy these to our IoT device, in this case the Ubuntu virtual machine. You can use any SCP tool to perform this activity, such as WinSCP, as well. Here is a screenshot of the files on my Ubuntu virtual machine:
For this scenario, I've called the downloaded Symantec Root CA file  root-CA.crt.

Once the files are copied over to a destination folder in your IoT device, you are now ready to test the connectivity, but in order to do that, we will first need to install and configure the AWS IoT Device SDK on our IoT device.

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

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