deep dive on aws iot

41
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Olawale Oladehin | Solutions Architect July 13, 2016 Deep Dive on AWS IoT

Upload: amazon-web-services

Post on 16-Apr-2017

459 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Deep Dive on AWS IoT

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Olawale Oladehin | Solutions Architect

July 13, 2016

Deep Dive on AWS IoT

Page 2: Deep Dive on AWS IoT

What to expect from the session

1. Overview of AWS IoT

2. Use IoT rules engine to process data and move

data to AWS services

3. Use IoT shadow, lifecycle events, and Amazon

ML for fleet management

Page 3: Deep Dive on AWS IoT

AWS IoT

Page 4: Deep Dive on AWS IoT

Select an AWS IoT Device SDK

• Based on open standards like Eclipse Paho

• C

• iOS (Swift)

• Android

• Node.js

• Python

• Java

Page 5: Deep Dive on AWS IoT

Securely connect device

• AWS IoT-generated certificates

• Use your own certificate

Page 6: Deep Dive on AWS IoT

First steps with AWS IoT

=+

Page 7: Deep Dive on AWS IoT

And then…

Page 8: Deep Dive on AWS IoT

IoT rules engine

Page 9: Deep Dive on AWS IoT

Rules engine

Page 10: Deep Dive on AWS IoT

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

Page 11: Deep Dive on AWS IoT

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:

Page 12: Deep Dive on AWS IoT

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:

Page 13: Deep Dive on AWS IoT

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:

Page 14: Deep Dive on AWS IoT

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

Page 15: Deep Dive on AWS IoT

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.

Page 16: Deep Dive on AWS IoT

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

Page 17: Deep Dive on AWS IoT

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”

}

}

],

}

Page 18: Deep Dive on AWS IoT

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”

}

}

],

}

Page 19: Deep Dive on AWS IoT

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

Page 20: Deep Dive on AWS IoT

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 Amazon Kinesis

stream

Publish to Firehose

Republish to AWS IoT

Publish to Amazon ES

Capture a CloudWatch

metric or change an alarm

Write to an SQS queue

Page 21: Deep Dive on AWS IoT

Rules engine features

• Versioning

• 2015-10-08 – Original version

• 2016-03-23-beta – Beta version released on specific date

• beta – Latest beta version (breaking changes!)

{

"sql": "expression",

"ruleDisabled": false,

"awsIotSqlVersion": "2015-03-23-beta",

"actions": [{

"republish": {

"topic": "my-mqtt-topic",

"roleArn": "arn:aws:iam::123456789012:role/my-iot-role"

}

}]}

Page 22: Deep Dive on AWS IoT

Rules engine features

• JSON collections

• get(array, int) – get item at index of array

• get(string, int) – get character at position of string

• get(object, key) – get value of key

• SUB SELECT from collections

• SELECT (SELECT v FROM e WHERE n = 'temperature') as

temperature FROM 'topic'

Page 23: Deep Dive on AWS IoT

Rules engine: Integrating data storage

Put object in an S3 bucket

Insert, update a

DynamoDB tablePublish to Firehose

Publish to Amazon ES

Publish to a Amazon Kinesis

stream

Page 24: Deep Dive on AWS IoT

ElasticSearch Integration

Page 25: Deep Dive on AWS IoT

Basic flow for using Amazon Elasticsearch

Service

1. Configure your Amazon ES domain

2. Use an IoT rule to send device data to the

Amazon ES domain you configured

3. Use Kibana to visualize your device data

Page 26: Deep Dive on AWS IoT
Page 27: Deep Dive on AWS IoT

Fleet management and IoT

operations

Page 28: Deep Dive on AWS IoT

Fleet management

• How many devices are currently connected?

• How many successful firmware updates have occurred

over the last 24 hours?

• What was the state of a subset of devices 24 hours ago?

• Can I predict when a device might need maintenance?

Page 29: Deep Dive on AWS IoT

AWS IoT Device Shadow

Page 30: Deep Dive on AWS IoT

Shadow topics – request

• /update

• /get

• /delete

Page 31: Deep Dive on AWS IoT

Shadow topics – response

• /update/accepted

• /get/accepted

• /delete/accepted

• /update/rejected

• /get/rejected

• /delete/rejected

Create operational metrics across your fleet of devices

Page 32: Deep Dive on AWS IoT

Additional shadow topics

• /update/documents

• Previous shadow state

• Current shadow state

• History of devices

• /update/delta

• Difference between reported and desired

• Audit trail of desired attribute changes

Page 33: Deep Dive on AWS IoT

Operational rules: Shadow metrics

"rule": {

"ruleName": ”deviceHealthMetrics”,

"ruleDisabled": false,

"sql": "SELECT state.reported.health AS health FROM ’$aws/things/+/shadow/update/accepted’

WHERE health = 1",

"description": ”Track the number of successful health checks from shadow topic",

"actions": [

{

”cloudwatchMetric": {

"roleArn": "arn:aws:iam::012345678901:role/iot-actions-role”,

”metricNamespace": ”IoTNamespace”,

”metricName": ”deviceHealth”,

”metricValue": ”1”,

”metricUnit": ”Count”

}

}

],

}

Page 34: Deep Dive on AWS IoT

Operational rules: Device history

"rule": {

"ruleName": ”shadowDocumentHistory”,

"ruleDisabled": false,

"sql": " SELECT current.state AS state, cast(timestamp as number) * 1000 AS timestampMillis

FROM '$aws/things/+/shadow/update/documents' ",

"actions": [

{

”elasticsearch": {

”endpoint": ”https://search-fleet-xxxx.us-east-1.es.amazonaws.com",

"roleArn": "arn:aws:iam::012345678901:role/iot-actions-role”,

“index”:”devices”,

“type”:”sensor”,

“id”:”${newuuid()}”,

}

}

],

}

Page 35: Deep Dive on AWS IoT

Lifecycle events

1. Publishes a message when a client connects or

disconnects

2. $aws/events/presence/connected/<clientId>

3. $aws/events/presence/disconnected/<clientid>

{

”clientId": ”a1sb2568s0d08s08d0sdkasldkfei",

”timestamp": 1460065233478,

”eventType": “disconnected”,

”clientInitiatedDisconnect": true,

”sessionIdentifier": “000000-000-0000-0000-0000000000”,

”principalIdentifier": “000000/ABCDEFGHIJKLM:user/user-id”,

}

Page 36: Deep Dive on AWS IoT

Amazon ML predict function

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

Page 37: Deep Dive on AWS IoT

Amazon ML Predict Function

Page 38: Deep Dive on AWS IoT

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

Page 39: Deep Dive on AWS IoT

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

Page 40: Deep Dive on AWS IoT

Summary

• Extract value from device data: rules engine

• Visualize your data: rules engine with AWS

Services

• Use IoT shadow, lifecycle events, and

Amazon ML for fleet management

Page 41: Deep Dive on AWS IoT

Thank You!@oladehin