AWS IoT is a managed cloud platform that lets connected devices easily and securely interact with cloud applications and other devices. As an IoT developer, you will need to interact with AWS services like Amazon Kinesis, AWS Lambda, and Amazon Machine Learning to get the most from your IoT application. In this session, we will do a deep dive on how to define rules in the Rules Engine, or retrieve the last known and desired state of device using Device Shadows, routing data from devices to AWS services to leverage the entire cloud for your Internet of Things application.
2. Goal: Answer these questions
1. How do I extract value from my device data?
Using IoT rules engine to process your data
2. How do I visualize my device data?
Connecting the rules engine to Elasticsearch/Kibana
3. How do I generate predictions?
Using Amazon Machine Learning predict function in
your IoT rules
4. Back to the questions
1. How do I extract value from my device data?
Using IoT rules engine to process messages
2. How do I visualize my device data?
Connecting the rules engine to Elasticsearch/Kibana
3. How do I generate predictions ?
Using Amazon Machine Learning predict function in
your IoT rules
6. Rules engine: Extracting value from messages
• Filter messages with certain criteria
• Transform the payload of messages
• React based on messages
• Move messages to other topics
• Move messages to other systems
• Predict changes based on trends
7. What is a rule?
ruleArn: arn:aws:iot:<region>:<account_id>:rule/<uniq_rule_name>
rule:
• ruleName: human-readable name
• description: human-readable description
• ruleDisabled: true/false
• sql: e.g. SELECT * FROM ‘pm/topic’
• actions:
• action 1:
• action 2:
8. What is a rule?
• ruleName: human-readable name
• description: human-readable description
• ruleDisabled: true/false
• sql: e.g. SELECT * FROM ‘pm/topic’
• actions:
• action 1:
• action 2:
9. What is a rule?
• ruleName: human-readable name
• description: human-readable description
• ruleDisabled: true/false
• sql: e.g. SELECT * FROM ‘pm/topic’
• actions:
• action 1:
• action 2:
10. Rules engine: Filter and transform
• Filter messages with certain criteria
• Transform the payload of messages
• React based on messages
• Move messages to other topics
• Move messages to other systems
• Predict changes based on trends
11. Rules engine: Filter and transform
• SQL
• SELECT * FROM topic WHERE condition
• SELECT status.space_id AS room_id FROM
'iot/tempSensors/#' WHERE temp > 50
• Functions (in SELECT or WHERE)
• String manipulation (regex support)
• Mathematical operations
• Context-based helper functions
• Crypto support
• UUID, timestamp, rand, etc.
12. Rules engine: React and move
• Filter messages with certain criteria
• Transform the payload of messages
• React based on messages
• Move messages to other topics
• Move messages to other systems
• Predict changes based on trends
13. Rules engine: React (and move)
"rule": {
"ruleName": "republishPredictions”,
"ruleDisabled": false,
"sql": "SELECT no AS id, cycle AS c_number FROM 'pm/topic' WHERE failure = 1",
"description": "Republish ids of engines that are predicted to fail within 30 cycles",
"actions": [
{
"republish": {
"topic": "pm/failures",
"roleArn": "arn:aws:iam::012345678901:role/iot-actions-role”
}
}
],
}
14. Rules engine: React (and move)
"rule": {
"ruleName": "republishPredictions”,
"ruleDisabled": false,
"sql": "SELECT no AS id, cycle AS c_number FROM 'pm/topic' WHERE failure = 1",
"description": "Republish ids of engines that are predicted to fail within 30 cycles",
"actions": [
{
"republish": {
"topic": "pm/failures",
"roleArn": "arn:aws:iam::012345678901:role/iot-actions-role”
}
}
],
}
15. Rules engine: Move messages to other systems
• Filter messages with certain criteria
• Transform the payload of messages
• React based on messages
• Move messages to other topics
• Move messages to other systems
• Predict changes based on trends
16. Rules engine: Move messages to other
systems
Invoke a Lambda function
Put object in an S3 bucket
Insert, update a
DynamoDB table
Publish to an SNS topic
or endpoint
Publish to a Kinesis stream
Publish to Firehose
Republish to AWS IoT
Publish to Elasticsearch
Capture a CloudWatch
metric or change an alarm
Write to SQS queue
17. 1. How do I extract value from my device data?
Using IoT rules engine to process messages
2. How do I visualize my device data?
Connecting the rules engine to Elasticsearch/Kibana
3. How do I generate predictions?
Using Amazon Machine Learning predict function in
your IoT rules
18. 1. How do I extract value from my device data ?
Using IoT Rules Engine to process messages
2. How do I visualize my device data?
Connecting the rules engine to Elasticsearch/Kibana
3. How do I generate predictions ?
Using Amazon Machine Learning (AML) predict
function in your IoT Rules
20. Basic flow for using Elasticsearch
1. Configure your Elasticsearch domain
2. Use an IoT rule to send device data to the
Elasticsearch domain you configured
3. Use Kibana to visualize your device data
23. 1. How do I extract value from my device data?
Using IoT rules engine to process messages
2. How do I visualize my device data?
Connecting the rules engine to Elasticsearch/Kibana
3. How do I generate predictions?
Using Amazon Machine Learning predict function in
your IoT rules
24. 1. How do I extract value from my device data ?
Using IoT Rules Engine to process messages
2. How do I visualize my device data ?
Connecting the Rules Engine to ElasticSearch / Kibana
3. How do I generate predictions?
Using Amazon Machine Learning predict function in
your IoT rules
26. Importance of the good predictions
Right balance depends on risk/cost ratio:
1. Predict a failure too soon = replacing a part
that doesn’t need repair yet – loss
2. No prediction = risk of sustaining a bigger loss
28. Basic flow for using predictions
1. Use an IoT rule to forward device data to S3
2. Train your Amazon ML model using the data from
S3
3. Use an IoT rule to:
• Obtain predicted value from real-time prediction
endpoint in Amazon ML
• Emit a CloudWatch metric (or trigger an alarm)
4. Use an IoT rule to emit details of a predicted failure
29. AWS IoT predict function for Amazon ML
machinelearning_predict(
'ml-XXXXXX',
'arn:aws:iam::<account_id>:role/<role>',
*).predictedLabel
ml-XXXXXX – Amazon ML predictor you trained
account_id – your account ID
role – a role in your account that:
• Has access to Amazon ML
• Part of a trust relationship b/w your account and IoT
32. Summary
• Extract value from device data: rules engine
• Visualize your data: rules engine with
Elasticsearch/Kibana integration
• Using predictions: machinelearning_predict()