Hands-on with AWS IoT
Julien Simon
Principal Technical Evangelist
Amazon Web Services

julsimon@amazon.com
@julsimon

07/11/2016
Agenda
•  Overview of AWS IoT
•  Devices & SDKs, with a focus on the Arduino Yún 
•  The MQTT protocol
•  Managing “things”
•  Routing AWS IoT messages to other AWS services
•  Debugging AWS IoT applications
•  And lots of AWS CLI, yeah!
DEVICE SDK
Set of client libraries to
connect, authenticate and
exchange messages
DEVICE GATEWAY
Communicate with devices via
MQTT and HTTP
AUTHENTICATION
AUTHORIZATION
Secure with mutual
authentication and encryption
RULES ENGINE
Transform messages
based on rules and
route to AWS Services
AWS
- - - - - 
3rd party
DEVICE SHADOW
Persistent thing state during
intermittent connections
APPLICATIONS
AWS IoT API
DEVICE REGISTRY
Identity and Management of
your things
Availability & Pricing
•  No minimum fee
•  You are only charged on the number of
incoming and outgoing messages
•  1 message = 512 bytes maximum
•  Free tier: 250K messages / month for 12
months
•  No charge when delivering to Amazon
S3, Amazon DynamoDB, AWS Lambda,
Amazon Kinesis, Amazon SNS, and
Amazon SQS.
Devices & SDKs
Official AWS IoT Starter Kits
Software platforms supported by AWS IoT
•  Arduino Yún: https://github.com/aws/aws-iot-device-sdk-arduino-yun 
•  Javascript: https://github.com/aws/aws-iot-device-sdk-js 
•  Embedded C: https://github.com/aws/aws-iot-device-sdk-embedded-C 
•  Android: https://github.com/aws/aws-sdk-android/ 
•  iOS: https://github.com/awslabs/aws-sdk-ios-samples 
•  Java (07/16): https://github.com/aws/aws-iot-device-sdk-java 
•  Python (07/16): https://github.com/aws/aws-iot-device-sdk-python
Personal picture
Hardware Shopping List
Software Shopping List

Arduino IDE and librairies 
http://arduino.org/software

Arduino Web Editor & Cloud Platform
https://aws.amazon.com/blogs/aws/
arduino-web-editor-and-cloud-platform-
powered-by-aws/ 

Tip: ArduinoJson, a JSON library for
embedded systems
https://github.com/bblanchon/ArduinoJson
Things
Managing things
•  Thing Registry
•  Secure Identity for Things
•  Secure Communications with Things

•  Fine-grained Authorization for:
–  Thing Management
–  Access to messages
–  Access to AWS services

AWS IoT is supported by AWS CloudFormation (07/16)
Creating a thing
% aws iot create-thing --thing-name myThing
% aws iot describe-thing --thing-name myThing
% aws iot list-things
You can use thing types and attributes to organize and tag your things (07/16)
http://docs.aws.amazon.com/iot/latest/developerguide/thing-types.html
Creating a certificate and keys
% aws iot create-keys-and-certificate
--set-as-active
--certificate-pem-outfile cert.pem
--public-key-outfile publicKey.pem
--private-key-outfile privateKey.pem

The AWS IoT root certificate, the thing certificate and the thing private key must be installed on your
device, e.g. https://github.com/aws/aws-iot-device-sdk-arduino-yun 



You can also use your own certificates (04/16), ECC cryptography (05/16), "
as well as just-in-time registration (08/16)
https://aws.amazon.com/blogs/mobile/use-your-own-certificate-with-aws-iot/
https://aws.amazon.com/blogs/iot/elliptic-curve-cryptography-and-forward-secrecy-support-in-aws-iot-3/ 
https://aws.amazon.com/blogs/aws/new-just-in-time-certificate-registration-for-aws-iot/
Creating a policy
% cat myPolicy.json
{
"Version": "2012-10-17",
"Statement": [{ "Effect": "Allow", "Action":["iot:*"],
"Resource": ["*"] }]
}

% aws iot create-policy
--policy-name PubSubToAnyTopic
--policy-document file://myPolicy.json
Assigning an identity to a Policy and a Thing
% aws iot attach-principal-policy
--policy-name PubSubToAnyTopic
--principal CERTIFICATE_ARN
% aws iot attach-thing-principal
--thing-name myThing
--principal CERTIFICATE_ARN
Arduino : connecting to AWS IoT
aws_iot_mqtt_client myClient;
if((rc = myClient.setup(AWS_IOT_CLIENT_ID)) == 0) {
// Load user configuration
if((rc = myClient.config(AWS_IOT_MQTT_HOST,
AWS_IOT_MQTT_PORT, AWS_IOT_ROOT_CA_PATH,
AWS_IOT_PRIVATE_KEY_PATH, AWS_IOT_CERTIFICATE_PATH)) == 0) {
if((rc = myClient.connect()) == 0) {
// We are connected
doSomethingUseful();
}
}
}
The MQTT protocol
Protocols supported by AWS IoT
•  MQTT over HTTPS to publish and subscribe"
(IPv4 and IPv6)
•  MQTT over WebSocket to publish and subscribe.
Security is managed with AWS Signatures v4.
•  HTTPS protocol to publish.
MQTT Protocol
MQTTS vs HTTPS: 

93x faster throughput
11.89x less battery to send
170.9x less battery to receive
50% less power to stay connected
8x less network overhead
Source:
http://stephendnicholas.com/archives/1217 
•  OASIS standard protocol (v3.1.1)
•  Lightweight transport protocol that is
useful for connected devices
•  Publish-subscribe with topics
•  MQTT is used on oil rigs, connected
trucks, and many more critical
applications
•  Until now, customers had to build,
maintain and scale a broker to use MQTT
with cloud applications
MQTT: device-to-device communication
mydevices/alert
MQTT: collect data from a device
mydevices/4
mydevices/4
MQTT: aggregate data from many devices
mydevices/#
mydevices/1
mydevices/2
mydevices/3
….
Amazon "
DynamoDB
Applications
MQTT: update a device
mydevices/4
mydevices/4
MQTT: QoS 0 (at most once)"

1
2
3
4
5
6
1,2,3,5,6
Publish QoS0
MQTT: QoS 1 (at least once)
1
2
3
4
5
4
1,2,3,4,5,6
6
PUBLISH QoS1
PUBLISH QoS1
PUBACK
MQTT.fx
http://mqttfx.jfx4ee.org/
Arduino : subscribing and publishing to a topic
if ((rc=myClient.subscribe(”myTopic", 1, msg_callback)) != 0)
{
Serial.println("Subscribe failed!");
Serial.println(rc);
}
if((rc = myClient.publish(”myTopic", msg, strlen(msg),
1, false)) != 0)
{
Serial.println("Publish failed!");
Serial.println(rc);
}
Arduino : callback for incoming messages
// Basic callback function that prints out the message
void msg_callback(char* src, int len) {
Serial.println("CALLBACK:");
for(int i = 0; i < len; i++) {
Serial.print(src[i]);
}
Serial.println("");
}
Rules
Granting AWS IoT access to AWS services
DynamoDB LambdaAmazon
Kinesis
Defining a trust policy for AWS IoT
% cat iot-role-trust.json
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"",
"Effect":"Allow",
"Principal":{
"Service":"iot.amazonaws.com"
},
"Action":"sts:AssumeRole"
}
]
}
Applying the trust policy to AWS IoT
% aws iam create-role --role-name my-iot-role
--assume-role-policy-document file://iot-role-trust.json
{
"Role": {
"AssumeRolePolicyDocument": {…},
"RoleId": "AROAJY7VZX5GEZ3Q7ILU4",
"CreateDate": "2016-03-19T12:07:03.904Z",
"RoleName": "my-iot-role",
"Path": "/",
"Arn": "arn:aws:iam::613904931467:role/my-iot-role"
}
}
1. AWS Services"
(Direct Integration)
Rules Engine
Actions
AWS IoT Rules
AWS "
Lambda
Amazon "
SNS
Amazon "
SQS
Amazon "
S3
Amazon "
Kinesis
Amazon "
DynamoDB
 Amazon RDS
Amazon "
Redshift
Amazon Glacier
Amazon "
EC2
3. External Endpoints"
(via Lambda and SNS)
Rules connect AWS IoT to
External Endpoints "
and AWS Services
2. Rest of AWS"
(via Amazon Kinesis, AWS
Lambda, Amazon S3, and
more)
Amazon
CloudWatch
Amazon "
Elasticsearch
Amazon 
Machine "
Learning
AWS IoT Rules Engine
Rule
Name
Description
SQL Statement
Array of Actions
Simple & Familiar Syntax
-  SQL Statement to define topic filter
-  Optional WHERE clause
-  Advanced JSON support

Many functions available
-  String manipulation (regex support)
-  Mathematical operations
-  Crypto support
-  UUID, Timestamp, rand, etc.
Creating a rule to write to DynamoDB
% cat topic1-dynamodb-rule.json
{
"sql": "SELECT * FROM 'topic1'",
"ruleDisabled": false,
"actions": [{
"dynamoDB": {
"tableName": "iot-topic1-table",
"roleArn": "arn:aws:iam::613904931467:role/my-iot-role",
"hashKeyField": "deviceId",
"hashKeyValue": "${deviceId}",
"rangeKeyField": "timestamp",
"rangeKeyValue": "${timestamp()}"
}
}]
}
% aws iot create-topic-rule --rule-name topic1-dynamodb-rule
--topic-rule-payload file://topic1-dynamodb-rule.json
Debugging
How can you debug AWS IoT applications?
•  Testing with MQTT.fx (or a similar tool) is not enough
•  CloudWatch Logs: the only way to see what is happening
inside AWS IoT
–  Permission issue
–  Rule issue
–  Incorrect JSON message
–  Etc.
•  These logs are not enabled by default
–  Define a policy allowing AWS IoT to access CloudWatch logs
–  Attach the policy to the AWS IoT role (same one as for external services)
Defining a policy for CloudWatch Logs
% cat iot-policy-logs.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:PutMetricFilter",
"logs:PutRetentionPolicy"
],
"Resource": [
"*"
]
}
]
}
Enabling CloudWatch Logs for AWS IoT
% aws iam create-policy
--policy-name my-iot-policy-logs --policy-document file://iot-policy-logs.json
{
"Policy": {
"PolicyName": "my-iot-policy-logs",
"CreateDate": "2016-03-19T12:24:16.072Z",
"AttachmentCount": 0,
"IsAttachable": true,
"PolicyId": "ANPAIK73XIV3QG5FF5TX6",
"DefaultVersionId": "v1",
"Path": "/",
"Arn": "arn:aws:iam::613904931467:policy/my-iot-policy-logs",
"UpdateDate": "2016-03-19T12:24:16.072Z"
}
}
% aws iam attach-role-policy --role-name my-iot-role
--policy-arn "arn:aws:iam::613904931467:policy/my-iot-policy-logs"
% aws iot set-logging-options
--logging-options-payload roleArn="arn:aws:iam::613904931467:role/my-iot-role",logLevel="INFO"
Demo : logging events in CloudWatch Logs
Now it’s your turn!

https://aws.amazon.com/iot/ 

https://aws.amazon.com/free/ 

https://aws.amazon.com/usergroups/europe/
More sessions
•  8/11, 10:00 A 60-minute tour of AWS Compute
•  9/11, 10:00 DevOps on AWS
•  9/11, 11:00 Running Docker clusters on AWS 
•  21/11, 11:00 Move fast, build things with AWS
•  22/11, 11:00 Deep Dive on Amazon RDS
Thank You !
Julien Simon
Principal Technical Evangelist
Amazon Web Services

julsimon@amazon.com
@julsimon

More Related Content

PDF
AWS Innovate: Building an Internet Connected Camera with AWS IoT- Tim Cruse
PDF
A 60-minute tour of AWS Compute (November 2016)
PDF
Workshop AWS IoT @ IoT World Paris
PDF
Keynote @ IoT World Paris
PDF
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015
PDF
Simplify Big Data with AWS
PDF
Influencer marketing: Buying and Selling Audience Impressions
PDF
AWS Big Data combo
AWS Innovate: Building an Internet Connected Camera with AWS IoT- Tim Cruse
A 60-minute tour of AWS Compute (November 2016)
Workshop AWS IoT @ IoT World Paris
Keynote @ IoT World Paris
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015
Simplify Big Data with AWS
Influencer marketing: Buying and Selling Audience Impressions
AWS Big Data combo

Viewers also liked (9)

PDF
Scale, baby, scale! (June 2016)
PDF
Machine Learning for everyone
PDF
Deep Dive on Amazon S3 (May 2016)
PDF
AWS Machine Learning Workshp
PDF
Hands-on with AWS IoT
PPTX
Intro to AWS Machine Learning
PDF
Deep Dive AWS CloudTrail
PDF
An Overview of AWS IoT (November 2016)
PDF
IoT: it's all about Data!
Scale, baby, scale! (June 2016)
Machine Learning for everyone
Deep Dive on Amazon S3 (May 2016)
AWS Machine Learning Workshp
Hands-on with AWS IoT
Intro to AWS Machine Learning
Deep Dive AWS CloudTrail
An Overview of AWS IoT (November 2016)
IoT: it's all about Data!
Ad

Similar to Hands-on with AWS IoT (November 2016) (20)

PDF
Connecting the Unconnected: IoT Made Simple
PDF
AWS NYC Meetup - May 2017 - "AWS IoT and Greengrass"
PDF
EE5111 a0195042 j_iot_project_report_update
PPTX
Gustavo Zastrow - Introduction to AWS IoT Core and MQTT
PPTX
Reply Webinar Online - Mastering AWS - IoT Foundations
PPTX
AWS IoT
PDF
PPTX
IoT Smart Home
PPTX
Web + AWS + IoT, how to
PDF
Intro to AWS IoT - Pop-up Loft London
PDF
An Intro to AWS IoT
PDF
Workshop AWS IoT @ SIDO
PPTX
Reply Bootcamp Rome - Mastering AWS - IoT Bootcamp
PDF
An Introduction to AWS IoT - Web Summit Lisbon
PPTX
Reply Webinar Online - Mastering AWS - IoT Advanced
PDF
An Introduction to AWS IoT
PPTX
Jeremy Cowan's AWS user group presentation "AWS Greengrass & IoT demo"
PDF
UNIT V.pdf
PPTX
Unit 6.pptx
PDF
Ecawed1230iot204 161228175642
Connecting the Unconnected: IoT Made Simple
AWS NYC Meetup - May 2017 - "AWS IoT and Greengrass"
EE5111 a0195042 j_iot_project_report_update
Gustavo Zastrow - Introduction to AWS IoT Core and MQTT
Reply Webinar Online - Mastering AWS - IoT Foundations
AWS IoT
IoT Smart Home
Web + AWS + IoT, how to
Intro to AWS IoT - Pop-up Loft London
An Intro to AWS IoT
Workshop AWS IoT @ SIDO
Reply Bootcamp Rome - Mastering AWS - IoT Bootcamp
An Introduction to AWS IoT - Web Summit Lisbon
Reply Webinar Online - Mastering AWS - IoT Advanced
An Introduction to AWS IoT
Jeremy Cowan's AWS user group presentation "AWS Greengrass & IoT demo"
UNIT V.pdf
Unit 6.pptx
Ecawed1230iot204 161228175642
Ad

More from Julien SIMON (20)

PDF
Implementing high-quality and cost-effiient AI applications with small langua...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
PDF
Arcee AI - building and working with small language models (06/25)
PDF
deep_dive_multihead_latent_attention.pdf
PDF
Deep Dive: Model Distillation with DistillKit
PDF
Deep Dive: Parameter-Efficient Model Adaptation with LoRA and Spectrum
PDF
Building High-Quality Domain-Specific Models with Mergekit
PDF
Tailoring Small Language Models for Enterprise Use Cases
PDF
Tailoring Small Language Models for Enterprise Use Cases
PDF
Julien Simon - Deep Dive: Compiling Deep Learning Models
PDF
Tailoring Small Language Models for Enterprise Use Cases
PDF
Julien Simon - Deep Dive - Optimizing LLM Inference
PDF
Julien Simon - Deep Dive - Accelerating Models with Better Attention Layers
PDF
Julien Simon - Deep Dive - Quantizing LLMs
PDF
Julien Simon - Deep Dive - Model Merging
PDF
An introduction to computer vision with Hugging Face
PDF
Reinventing Deep Learning
 with Hugging Face Transformers
PDF
Building NLP applications with Transformers
PPTX
Building Machine Learning Models Automatically (June 2020)
Implementing high-quality and cost-effiient AI applications with small langua...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Trying to figure out MCP by actually building an app from scratch with open s...
Arcee AI - building and working with small language models (06/25)
deep_dive_multihead_latent_attention.pdf
Deep Dive: Model Distillation with DistillKit
Deep Dive: Parameter-Efficient Model Adaptation with LoRA and Spectrum
Building High-Quality Domain-Specific Models with Mergekit
Tailoring Small Language Models for Enterprise Use Cases
Tailoring Small Language Models for Enterprise Use Cases
Julien Simon - Deep Dive: Compiling Deep Learning Models
Tailoring Small Language Models for Enterprise Use Cases
Julien Simon - Deep Dive - Optimizing LLM Inference
Julien Simon - Deep Dive - Accelerating Models with Better Attention Layers
Julien Simon - Deep Dive - Quantizing LLMs
Julien Simon - Deep Dive - Model Merging
An introduction to computer vision with Hugging Face
Reinventing Deep Learning
 with Hugging Face Transformers
Building NLP applications with Transformers
Building Machine Learning Models Automatically (June 2020)

Recently uploaded (20)

PDF
August Patch Tuesday
PDF
Five Habits of High-Impact Board Members
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Getting Started with Data Integration: FME Form 101
PPTX
The various Industrial Revolutions .pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Unlock new opportunities with location data.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPT
Geologic Time for studying geology for geologist
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Hybrid model detection and classification of lung cancer
DOCX
search engine optimization ppt fir known well about this
PPTX
O2C Customer Invoices to Receipt V15A.pptx
August Patch Tuesday
Five Habits of High-Impact Board Members
Univ-Connecticut-ChatGPT-Presentaion.pdf
Getting Started with Data Integration: FME Form 101
The various Industrial Revolutions .pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
observCloud-Native Containerability and monitoring.pptx
Unlock new opportunities with location data.pdf
Tartificialntelligence_presentation.pptx
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
A novel scalable deep ensemble learning framework for big data classification...
Taming the Chaos: How to Turn Unstructured Data into Decisions
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Geologic Time for studying geology for geologist
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Benefits of Physical activity for teenagers.pptx
NewMind AI Weekly Chronicles – August ’25 Week III
Hybrid model detection and classification of lung cancer
search engine optimization ppt fir known well about this
O2C Customer Invoices to Receipt V15A.pptx

Hands-on with AWS IoT (November 2016)

  • 1. Hands-on with AWS IoT Julien Simon Principal Technical Evangelist Amazon Web Services julsimon@amazon.com @julsimon 07/11/2016
  • 2. Agenda •  Overview of AWS IoT •  Devices & SDKs, with a focus on the Arduino Yún •  The MQTT protocol •  Managing “things” •  Routing AWS IoT messages to other AWS services •  Debugging AWS IoT applications •  And lots of AWS CLI, yeah!
  • 3. DEVICE SDK Set of client libraries to connect, authenticate and exchange messages DEVICE GATEWAY Communicate with devices via MQTT and HTTP AUTHENTICATION AUTHORIZATION Secure with mutual authentication and encryption RULES ENGINE Transform messages based on rules and route to AWS Services AWS - - - - - 3rd party DEVICE SHADOW Persistent thing state during intermittent connections APPLICATIONS AWS IoT API DEVICE REGISTRY Identity and Management of your things
  • 4. Availability & Pricing •  No minimum fee •  You are only charged on the number of incoming and outgoing messages •  1 message = 512 bytes maximum •  Free tier: 250K messages / month for 12 months •  No charge when delivering to Amazon S3, Amazon DynamoDB, AWS Lambda, Amazon Kinesis, Amazon SNS, and Amazon SQS.
  • 6. Official AWS IoT Starter Kits
  • 7. Software platforms supported by AWS IoT •  Arduino Yún: https://github.com/aws/aws-iot-device-sdk-arduino-yun •  Javascript: https://github.com/aws/aws-iot-device-sdk-js •  Embedded C: https://github.com/aws/aws-iot-device-sdk-embedded-C •  Android: https://github.com/aws/aws-sdk-android/ •  iOS: https://github.com/awslabs/aws-sdk-ios-samples •  Java (07/16): https://github.com/aws/aws-iot-device-sdk-java •  Python (07/16): https://github.com/aws/aws-iot-device-sdk-python
  • 10. Software Shopping List Arduino IDE and librairies http://arduino.org/software Arduino Web Editor & Cloud Platform https://aws.amazon.com/blogs/aws/ arduino-web-editor-and-cloud-platform- powered-by-aws/ Tip: ArduinoJson, a JSON library for embedded systems https://github.com/bblanchon/ArduinoJson
  • 12. Managing things •  Thing Registry •  Secure Identity for Things •  Secure Communications with Things •  Fine-grained Authorization for: –  Thing Management –  Access to messages –  Access to AWS services AWS IoT is supported by AWS CloudFormation (07/16)
  • 13. Creating a thing % aws iot create-thing --thing-name myThing % aws iot describe-thing --thing-name myThing % aws iot list-things You can use thing types and attributes to organize and tag your things (07/16) http://docs.aws.amazon.com/iot/latest/developerguide/thing-types.html
  • 14. Creating a certificate and keys % aws iot create-keys-and-certificate --set-as-active --certificate-pem-outfile cert.pem --public-key-outfile publicKey.pem --private-key-outfile privateKey.pem The AWS IoT root certificate, the thing certificate and the thing private key must be installed on your device, e.g. https://github.com/aws/aws-iot-device-sdk-arduino-yun You can also use your own certificates (04/16), ECC cryptography (05/16), " as well as just-in-time registration (08/16) https://aws.amazon.com/blogs/mobile/use-your-own-certificate-with-aws-iot/ https://aws.amazon.com/blogs/iot/elliptic-curve-cryptography-and-forward-secrecy-support-in-aws-iot-3/ https://aws.amazon.com/blogs/aws/new-just-in-time-certificate-registration-for-aws-iot/
  • 15. Creating a policy % cat myPolicy.json { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action":["iot:*"], "Resource": ["*"] }] } % aws iot create-policy --policy-name PubSubToAnyTopic --policy-document file://myPolicy.json
  • 16. Assigning an identity to a Policy and a Thing % aws iot attach-principal-policy --policy-name PubSubToAnyTopic --principal CERTIFICATE_ARN % aws iot attach-thing-principal --thing-name myThing --principal CERTIFICATE_ARN
  • 17. Arduino : connecting to AWS IoT aws_iot_mqtt_client myClient; if((rc = myClient.setup(AWS_IOT_CLIENT_ID)) == 0) { // Load user configuration if((rc = myClient.config(AWS_IOT_MQTT_HOST, AWS_IOT_MQTT_PORT, AWS_IOT_ROOT_CA_PATH, AWS_IOT_PRIVATE_KEY_PATH, AWS_IOT_CERTIFICATE_PATH)) == 0) { if((rc = myClient.connect()) == 0) { // We are connected doSomethingUseful(); } } }
  • 19. Protocols supported by AWS IoT •  MQTT over HTTPS to publish and subscribe" (IPv4 and IPv6) •  MQTT over WebSocket to publish and subscribe. Security is managed with AWS Signatures v4. •  HTTPS protocol to publish.
  • 20. MQTT Protocol MQTTS vs HTTPS:  93x faster throughput 11.89x less battery to send 170.9x less battery to receive 50% less power to stay connected 8x less network overhead Source: http://stephendnicholas.com/archives/1217 •  OASIS standard protocol (v3.1.1) •  Lightweight transport protocol that is useful for connected devices •  Publish-subscribe with topics •  MQTT is used on oil rigs, connected trucks, and many more critical applications •  Until now, customers had to build, maintain and scale a broker to use MQTT with cloud applications
  • 22. MQTT: collect data from a device mydevices/4 mydevices/4
  • 23. MQTT: aggregate data from many devices mydevices/# mydevices/1 mydevices/2 mydevices/3 …. Amazon " DynamoDB Applications
  • 24. MQTT: update a device mydevices/4 mydevices/4
  • 25. MQTT: QoS 0 (at most once)" 1 2 3 4 5 6 1,2,3,5,6 Publish QoS0
  • 26. MQTT: QoS 1 (at least once) 1 2 3 4 5 4 1,2,3,4,5,6 6 PUBLISH QoS1 PUBLISH QoS1 PUBACK
  • 28. Arduino : subscribing and publishing to a topic if ((rc=myClient.subscribe(”myTopic", 1, msg_callback)) != 0) { Serial.println("Subscribe failed!"); Serial.println(rc); } if((rc = myClient.publish(”myTopic", msg, strlen(msg), 1, false)) != 0) { Serial.println("Publish failed!"); Serial.println(rc); }
  • 29. Arduino : callback for incoming messages // Basic callback function that prints out the message void msg_callback(char* src, int len) { Serial.println("CALLBACK:"); for(int i = 0; i < len; i++) { Serial.print(src[i]); } Serial.println(""); }
  • 30. Rules
  • 31. Granting AWS IoT access to AWS services DynamoDB LambdaAmazon Kinesis
  • 32. Defining a trust policy for AWS IoT % cat iot-role-trust.json { "Version":"2012-10-17", "Statement":[ { "Sid":"", "Effect":"Allow", "Principal":{ "Service":"iot.amazonaws.com" }, "Action":"sts:AssumeRole" } ] }
  • 33. Applying the trust policy to AWS IoT % aws iam create-role --role-name my-iot-role --assume-role-policy-document file://iot-role-trust.json { "Role": { "AssumeRolePolicyDocument": {…}, "RoleId": "AROAJY7VZX5GEZ3Q7ILU4", "CreateDate": "2016-03-19T12:07:03.904Z", "RoleName": "my-iot-role", "Path": "/", "Arn": "arn:aws:iam::613904931467:role/my-iot-role" } }
  • 34. 1. AWS Services" (Direct Integration) Rules Engine Actions AWS IoT Rules AWS " Lambda Amazon " SNS Amazon " SQS Amazon " S3 Amazon " Kinesis Amazon " DynamoDB Amazon RDS Amazon " Redshift Amazon Glacier Amazon " EC2 3. External Endpoints" (via Lambda and SNS) Rules connect AWS IoT to External Endpoints " and AWS Services 2. Rest of AWS" (via Amazon Kinesis, AWS Lambda, Amazon S3, and more) Amazon CloudWatch Amazon " Elasticsearch Amazon Machine " Learning
  • 35. AWS IoT Rules Engine Rule Name Description SQL Statement Array of Actions Simple & Familiar Syntax -  SQL Statement to define topic filter -  Optional WHERE clause -  Advanced JSON support Many functions available -  String manipulation (regex support) -  Mathematical operations -  Crypto support -  UUID, Timestamp, rand, etc.
  • 36. Creating a rule to write to DynamoDB % cat topic1-dynamodb-rule.json { "sql": "SELECT * FROM 'topic1'", "ruleDisabled": false, "actions": [{ "dynamoDB": { "tableName": "iot-topic1-table", "roleArn": "arn:aws:iam::613904931467:role/my-iot-role", "hashKeyField": "deviceId", "hashKeyValue": "${deviceId}", "rangeKeyField": "timestamp", "rangeKeyValue": "${timestamp()}" } }] } % aws iot create-topic-rule --rule-name topic1-dynamodb-rule --topic-rule-payload file://topic1-dynamodb-rule.json
  • 38. How can you debug AWS IoT applications? •  Testing with MQTT.fx (or a similar tool) is not enough •  CloudWatch Logs: the only way to see what is happening inside AWS IoT –  Permission issue –  Rule issue –  Incorrect JSON message –  Etc. •  These logs are not enabled by default –  Define a policy allowing AWS IoT to access CloudWatch logs –  Attach the policy to the AWS IoT role (same one as for external services)
  • 39. Defining a policy for CloudWatch Logs % cat iot-policy-logs.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:PutMetricFilter", "logs:PutRetentionPolicy" ], "Resource": [ "*" ] } ] }
  • 40. Enabling CloudWatch Logs for AWS IoT % aws iam create-policy --policy-name my-iot-policy-logs --policy-document file://iot-policy-logs.json { "Policy": { "PolicyName": "my-iot-policy-logs", "CreateDate": "2016-03-19T12:24:16.072Z", "AttachmentCount": 0, "IsAttachable": true, "PolicyId": "ANPAIK73XIV3QG5FF5TX6", "DefaultVersionId": "v1", "Path": "/", "Arn": "arn:aws:iam::613904931467:policy/my-iot-policy-logs", "UpdateDate": "2016-03-19T12:24:16.072Z" } } % aws iam attach-role-policy --role-name my-iot-role --policy-arn "arn:aws:iam::613904931467:policy/my-iot-policy-logs" % aws iot set-logging-options --logging-options-payload roleArn="arn:aws:iam::613904931467:role/my-iot-role",logLevel="INFO"
  • 41. Demo : logging events in CloudWatch Logs
  • 42. Now it’s your turn! https://aws.amazon.com/iot/ https://aws.amazon.com/free/ https://aws.amazon.com/usergroups/europe/
  • 43. More sessions •  8/11, 10:00 A 60-minute tour of AWS Compute •  9/11, 10:00 DevOps on AWS •  9/11, 11:00 Running Docker clusters on AWS •  21/11, 11:00 Move fast, build things with AWS •  22/11, 11:00 Deep Dive on Amazon RDS
  • 44. Thank You ! Julien Simon Principal Technical Evangelist Amazon Web Services julsimon@amazon.com @julsimon