Executing Remote Operations with AWS IoT Jobs: A Hands-On Tutorial
What is a Job?
A Job is a remote operation that is sent to and executed on one or more devices connected to AWS IoT. For example, you can define a Job that instructs a set of devices to download and install application or firmware updates, reboot, rotate certificates, or perform remote troubleshooting operations.
How to create a Job?
You must create a job document first.
The Job Document is a description of the remote operations to be performed a Job
Target
When you create a Job, you specify a list of targets that are the devices that should perform the operations. The targets can be things or thing groups or both. The Jobs feature sends a message to each target to inform it that a Job is available.
Job Execution
A Job execution is an instance of a Job on a target device. The target starts an execution of a Job by downloading the Job document. It then performs the operations specified in the document, and reports its progress to AWS IoT.
Prepare to run a remote operation using Jobs
- Setup download location (Device Client)
1 | mkdir -p /home/ubuntu/workshop_dc/downloadLocation |
Check if the process successful
1 | sudo tail -F /var/log/aws-iot-device-client/aws-iot-device-client.log |
AWS IoT Job using embedded-c SDK
Launch an EC2.
- AMI: ubuntu
- t2.micro
Networking:
- VPC CIDR: 10.1.0.0/16
- Public Subnet: 10.1.0.0/24
Connect to the instance and install the necessary packages
Installation
1 | sudo apt-get install vim git curl |
Create Things
- Create Thing
- Enter Thing Name, press “Next”
- Select Auto-generate a new certificate
Policy
Make sure that the certificate you create have bind to policy with enough permisssion
iot: Connect
iot: Receive
iot: Publish
iot: Subscribe
Download Certificate
Upload certificate to EC2
1 | scp -i <local ssh private key> <cert_name>pem.crt admin@ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com:/home/admin/aws-iot-device-sdk-embedded-c/build/bin/certificates/ |
Upload private key
1 | scp -i TestKeyAccess.pem debace3e049b44eb15d67fad8ab17763cc575604f4d4a1451cc62cd4ef1498ed-private.pem.key ubuntu@ec2-54-167-159-68.compute-1.amazonaws.com:/home/ubuntu/aw |
Upload certificates
1 | scp -i TestKeyAccess.pem debace3e049b44eb15d67fad8ab17763cc575604f4d4a1451cc62cd4ef1498ed-certificate.pem.crt ubuntu@ec2-54-167-159-68.compute-1.amazonaws.com:/home/ubuntu/aws-iot-device-sdk-embedded-c/build/bin/certificates |
Upload AmazonRootCA1.pem
1 | scp -i TestKeyAccess.pem AmazonRootCA1.pem ubuntu@ec2-54-167-159-68.compute-1.amazonaws.com:/home/ubuntu/aws-iot-device-sdk-embedded-c/build/bin/certificates |
AWS IoT Jobs Demo
1 | sudo apt install curl libmosquitto-dev mosquitto |
Create Job
1 | aws iot create-job --job-id t12 --targets <YOUR_THING_ARN> \ |
Execute Job on the target device run the demo program with device credentials
1 | jobs_demo_mosquitto -n device1 -h abcdefg123.iot.us-east-1.amazonaws.com \ |
Build the demo program
1 | cd /aws-iot-device-sdk-embedded-c/demos/jobs/jobs_demo_mosquitto |
1 | ./jobs_demo_mosquitto |
1 | ./jobs_demo_mosquitto -n <Thing Name> -h <YOUR_IOT_ENDPOINT> \ |
Endpoint: a2t2vimlyuhccy-ats.iot.us-east-1.amazonaws.com
1 | ./jobs_demo_mosquitto -n |
Check AWSIoTLogv2
The Download files by Job can be found in the tmp
Reference
[+] AWS Workshop- https://catalog.workshops.aws/getstartedwithawsiot/en-US/chapter5-jobs/10-dc-setup