Skip to main content

Configuring Your First IoT Device

Hands-On Lab


Photo of

Training Architect





In this live AWS environment, you will learn how to configure an 'IoT device' using AWS IoT. In this case, because we can't provide you with a physical device, we will use an EC2 instance running a Jupyter to mimic an IoT device.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Configuring Your First IoT Device


In this lab, we're going to create, register, and configure an IoT device using AWS IoT. We'll also be creating an IoT certificate and IoT policy and sending messages to our IoT device.

Sign in to the AWS Management Console with the username and password provided on the lab instructions page.

Then, sign in to the Jupyter Notebook using the provided sign-in link and password.

Navigate to the IoT section of the AWS Management Console by opening the Services dropdown at the top of the page and searching for "IoT". Choose the IoT Core option.

Next, navigate to your Jupyter Notebook window, and open the FirstIoTDevice.ipynb file in a new browser tab.

Create an IoT Device, Certificate, and Policy

In the AWS Console, click the Get started button. Select the Manage option in the left sidebar, and then click Register a thing.

In the menu that opens, click Create a single thing. Name the thing "penguin-sat". Under Apply a type to this thing, click the Create a type button. Name the thing type "sat", and click Create thing type. Next, under Add this thing to a group, click Create group. In the Create a thing group menu, name the group "device-sats". Under the Set group attributes header, type "location" for the Attribute key and type "space" for Value. Click Create thing group, then click Next to move on to the next step.

On the Add a certificate for your thing page, click the Create certificate button. This should generate a certificate. However, if you receive an error for any reason, wait a moment and then try again.

Next, download the certificate, public key, and private key. Next, we need to download a root CA for AWS IoT. Open the Download link in a new tab, and select 2048-bit key: Amazon Root CA 1. When it opens in a new browser page, save the certificate as "AmazonRootCA1" to your Downloads folder. Switch back to the Amazon IoT Console and click the Activate button.

Next, click the Attach a policy button. On the Add a policy for your thing page, click the Register Thing button. You should see a success message that says "Successfully registered your thing". However, we need an IoT policy before our IoT thing can send messages to an IoT topic. Let's set this up next.

Click Secure in the left sidebar, then select Policies and click the Create a policy button. Name the policy "sat-pol". Then, type "iot" in the Action field, and click iot:** in the dropdown menu. The Resource ARN field will automatically populate with "arn:aws:iot:us-east-1:533390822900:topic/replaceWithATopic". Delete the text in this field, and replace it with "". Under Effect, check the checkbox next to Allow. Then click the Create** button.

Now let's attach the policy to the certificate we created earlier. Navigate to the Certificates menu. Under the Certificates heading, you should see a box with an Active certificate. Click the ... icon, and choose Attach policy in the dropdown menu. In the Attach policies to certificate(s) menu, check the checkbox next to sat-pol, and click the Attach button.

Select Test in the left sidebar. In the Subscriptions menu, enter "penguinfeed/1" for the Subscription topic. Click Subscribe, then Publish. We should see a message that says "Hello from AWS IoT console".

Send Data with Your IoT Device

Navigate to your Jupyter Notebook browser window. The first thing we need to do is install the AWS IoT SDK for Python. Select the !pip install AWSIoTPythonSDK cell and click the Run button at the top of the page. Next, we need to make sure that the SSL version is 1.0.1 or greater. Select and run the second cell.

Next, run the Import some dependencies we'll use to send data to the Topic from the "IoT Device" of this EC2 Instance section to import the dependencies we need.

In the Set some initial variables section, we will need to fill in some information. The BROKER_PATH can be found by clicking Settings in our AWS IoT window and copying the text in the Endpoint field. Paste this text in the BROKER_PATH line.

Next, we need to make the certificates we downloaded earlier available to be used by our code. Navigate to your Jupyter Notebook Home page browser tab. Click the Upload button. In the menu that opens, locate the four files we downloaded earlier (they will most likely be in your Downloads folder). Select the files, and click Open. Once these files appear in the Jypyter Notebook file list, click the Upload button next to each one of them. Then, copy the numbers at the beginning of the certificate and key file names (it should be the same value for all three of them). For example, if the private key name is 522107a270-private.pem.key, copy 522107a270 to your clipboard.

Go back to your FirstIoTDevice Jupyter Notebook browser tab, and locate the Set some initial variables section. Uncomment the lines that begin with PRIVATE_KEY_PATH and CERTIFICATE_PATH by removing the #.

PRIVATE_KEY_PATH = `./14e764a6a2-private.pem.key`
CERTIFICATE_PATH = `./14e764a6a2-certificate.pem.cert`

Next, replace the numbers at the beginning of both paths with the value that we just copied.

PRIVATE_KEY_PATH = `./522107a270-private.pem.key`
CERTIFICATE_PATH = `./522107a270-certificate.pem.cert`

Next, run the cell by clicking the Run button at the top of the screen.

Go back to your AWS IoT Console window and navigate to the penguinfeed/1 subscription. We're going to attempt to send a message to this feed using AWS IoT. In the Jupyter Notebook window, run the Create and Configure the IoT Client cell. We should see a message in the penguinfeed/1 feed that says "connected".

Now let's try sending a larger message to our penguinfeed/1 subscription. Run the Create and Send Payloads to the IoT Topic cell in your Jupyter Notebook tab. You should see many messages appear rapidly in the penguinfeed/1 message feed.


Congratulations, you've successfully completed this lab!