AI/ML, AWS, Cloud Computing, Internet of Things (IoT)

4 Mins Read

Create IoT Custom Job using AWS IoT Device Management

Voiced by Amazon Polly

Introduction

Once the IoT devices are in production, if a new use case or application comes to that device, we will go over the air update (OTA) to update the new firmware into the component. When fresh firmware becomes available, the device will reboot and resume working with the current updated applications.

In this blog, we will look at how to create a custom job using AWS IoT device management and Amazon S3.

Architecture Diagram

device1

 

Step-by-Step Guide

We don’t have any hardware for demonstration purposes; therefore, we’ll use an AWS Cloud9 environment to perform the custom IoT job.

Create S3 Bucket:

  1. Log in to the AWS Management Console and navigate to the S3 Management Console, where you will create an S3 bucket called testing-Custom-iot-job.
  2. If the bucket title is not available, use another available name.

Create a dependency file and job configuration file:

  1. Before we submitted the job and handle it at the devices using code, we must first prepare the dependency and job configuration files.
  2. Make a file called iot_custom_job.txt with some dummy data for this tutorial. Make a file called iot_custom_job.txt and paste the following text into it.

3. Upload the iot_custom_job.txt file into the testing-Custom-iot-job bucket and copy the file URL.

4. The path of a configuration file stored in an S3 bucket will be specified in the job. The devices will acquire the configuration file as part of the job processing.

5. The job configuration file is just in JSON format and does not have a predefined schema.

6. Make a file called job_config.json and put the configuration text below into it which also consists of the copied file path of iot_custom_job.txt.

Upload this file into the S3 bucket. Make sure your region is changed accordingly.

Register the device as a Thing:

  1. Go to the AWS IoT Core console, select Policies from the secure menu, and then click Create a policy.
  2. Enter custom_iot_job_policy as the policy name, Action as “iot:*”, Resource ARN as “*”, Effect as Allow, and click the Create button.
  3. To create a thing under the Manage option click the Things option and click on the Register a thing option. Choose the Create a single thing option.
  4. On the Add your device to the thing Screen, enter the device name as testing_device and choose the Next option.
  5. Click on Auto-generate a new certificate then click Next. This will generate device certifications for authentication purposes.
  6. AWS IoT will support X.509 client certificates and attach previously created policy then click create Thing.
  7. On the certification screen download A private key, A public key, certification for the thing, and A root CA for AWS.
  8. Make sure all certificates are downloaded these will requires in the feature. Finally, go to the setting page of the IoT console and make note of the MQTT endpoint.

Configure Cloud9 Environment:

Amazon Web Services AWS Cloud9 is a cloud-based integrated development environment (IDE).

  1. On the AWS Cloud9 console choose Create environment, enter test_envirnment as the name and click on the Next step
  2. Choose Create a new instance for environment (EC2) as environment type, select instance type t3.small, and platform as Ubuntu.
  3. On the next screen, click Create environment.
  4. Once the environment is created logo into int and run the following commands in the terminals.

5. Now all the necessary components are installed and upload the device certificates file, private key, and AmzoneRootCA file using the file option on the left corner and upload a local file.

Job-Handling Device Code:

  1. In the Cloud9 environment, create a new job_handler.py file. Copy-paste the following code into the file.

2. In the above replace {BROKER-ADDRESS} as the MQTT endpoint which is copied in the previous section and replace AmazonRootCA1.pem, {PRIVATE-KEY}, {X509-CERTIFICATE} as appropriate file names which are present in the directory, make sure file names must match as it’s in the environment.

3. Run the python code in the terminal using python job_handler.py. Maintain the Cloud9 on a separate browser tab.

Create a job in AWS IoT Core:

  1. On AWS IoT Console under the Manage menu, Click Jobs and then click on the Create button.
  2. Choose the job as Create custom job then click Next, enter the job name as testing_job and click Next.
  3. On Job targets choose Things to run this job and select the previously created thing which is testing_device.
  4. On the job document select From File option then select job_config.json from the S3 bucket which we created previously.
  5. At Pre-sign resource URLs choose to Create a role and provide the name iot_job_s3_access as the role name and click create.
  6. On the next screen select Snapshot from the job run type and click submit. The job has been created.

Testing and Result:

  1. Go to the AWS Cloud9 environment, which is previously opened in the browser tab, we can find the job was successfully run and the file will be downloaded and placed in the same folder.

device2

device3

Conclusion

Thus, we have seen how to do the custom IoT job using AWS IoT device management. This custom job helps to upload files or firmware to the device.  By using AWS IoT device management, we can do custom jobs, OTA (Over the Air update), and remote jobs like rebooting, etc.

About CloudThat

CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best-in-industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding IoT Device Management and I will get back to you quickly.

To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.

FAQs

1. What is the use case of AWS IoT Device management?

ANS: – AWS IoT Device Management simplifies the secure onboarding, organization, monitoring, and remote management of IoT devices at scale.

2. What kinds of jobs are supported by AWS IoT Device management?

ANS: – Custom job, FreeRTOS OTA update job, and Greengrass V1 Core update job.

WRITTEN BY Vasanth Kumar R

Vasanth Kumar R works as a Sr. Research Associate at CloudThat. He is highly focused and passionate about learning new cutting-edge technologies including Cloud Computing, AI/ML & IoT/IIOT. He has experience with AWS and Azure Cloud Services, Embedded Software, and IoT/IIOT Development, and also worked with various sensors and actuators as well as electrical panels for Greenhouse Automation.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!