SlideShare a Scribd company logo
1 of 26
Download to read offline
AWS IoT主要功能
一、​Device gateway
遙控器與燈泡都透過MQTT與AWS IoT溝通,遙控器publish command、燈泡subscribe +
listen command,把AWS IoT當作broker使用。
二、​Rules Engine
AWS IoT收到publish過來的資料,做完資料轉換後再傳到有subscribe的裝置上。
三、​Rules actions
Rule Engine除了可以控制傳進來的資訊,轉換後再傳給device,除此之外也可以傳給其他端
點,例如AWS Lambda functions 、 DynamoDB table 或是 Simple Notification Service (SNS)
讓通知訊息可以傳到手機端。
四、​Device Shadows
AWS IoT除了支援註冊裝置外,也可創造裝置的虛擬影子,該影子在實體裝置關閉時不會消
失,會代替實體裝置繼續接收訊息,等到實體裝置上線後,影子會再把目前最新的狀態傳送給
實體裝置,來確保資料不會因為裝置關機或斷線造成落差。
五、​Build solutions
AWS IoT可以很簡單的建立app來控制裝置,但app並不是一直和裝置處於連線的狀態,而是
透過REST API來取得裝置(的影子)目前的狀態,進而進行操作。
設定Rule Engine
1. 先設定​IAM​來管理使用者及存取權限 → Role → Create New Role → Attach Policy (選
擇AWSIoTRuleActions) → Finish
2. 接著設定該Role的Polity, Role → Inline Policies (Create one) → 選擇Policy
Generator (若想自行寫json,可選擇Custom) → 照下圖,Service選擇Publish、ARN
填寫arn:aws:iot:​us-west-2​:​964391593426​:topic/{{topic}},就可以開啟Publish的權
限。
​
3. 接著使用AWS IoT新增規則(Create a rule),填好要過濾的規則後並選擇【AWS IoT
Republish】,再填寫要轉送的topic以及剛剛申請好的testRole。
最後再發送payload到my/topic,就會也轉送一份到/test,完成整個Rule。
AWS IoT收費機制
AWS IoT Device SDK for Node.js
CA certificate可直接從官網下載
*調整Authorization
===========名詞解釋=============
Amazon Resource Name (ARN)
表示 AWS 內的資源,包含以冒號分隔的多個欄位:
最前兩節固定為 aws 與 arn
服務名稱,例如 iam, dynamodb
region, 例如 ap-northeast-1, 某些服務可省略
account, 帳號號碼(一堆數字,不帶分隔符號),可省略
resource identifier,依照各服務而有差異;可能是 *, aaaa, aaa/bbb, aaa:bbb 等格
式,在AWS IOT為Policy
AWS Identity and Access Management (IAM)
管理 IAM 使用者​及​其存取權​ – 您可以在 IAM 中建立使用者,為他們指派個別的安全登入資料 (換
句話說,就是存取金鑰、密碼和​多重驗證​裝置),或請求臨時的安全登入資料,為使用者提供 AWS
服務和資源的存取權。您可以管理許可以控制使用者可執行的操作。
管理 IAM 角色​及其​許可​ – 您可以在 IAM 中建立角色和管理許可,以控制擔任該角色的實體或
AWS 服務可執行的操作。您也可以定義允許擔任該角色的實體。
管理聯合身分使用者​及其​許可​ – 您可以啟用聯合身分功能,以允許企業中的現有身分 (使用者、群
組和角色) 存取 AWS 管理主控台、呼叫 AWS API 以及存取資源,而不必為每個身分建立 IAM 使
用者。
===============================
1. thingShadow class必須先register後才能進行操作,如get, update等
等。
2.
state
desired
The desired state of the thing. Applications can write to this portion of the document
to update the state of a thing without having to directly connect to a thing.
reported
The reported state of the thing. Things write to this portion of the document to report
their new state. Applications read this portion of the document to determine the state
of a thing.
metadata
Information about the data stored in the state section of the document. This includes
timestamps, in Epoch time, for eac
3. 7688必須先安裝AWS CLI: pip install awscli
4. 建立Certificate相關檔案: ​aws iot create-keys-and-certificate
--set-as-active --certificate-pem-outfile cert.pem
--public-key-outfile publicKey.pem --private-key-outfile
privateKey.pem
便會產出3個相關的檔案
5. 補充資料
AWS CLI語法
Available Commands
● accept-certificate-transfer
● attach-principal-policy ​(o)
● attach-thing-principal ​(o)
● cancel-certificate-transfer
● create-certificate-from-csr
● create-keys-and-certificate ​(o)
● create-policy ​(o)
● create-policy-version
● create-thing ​(o)
● create-topic-rule
● delete-certificate
● delete-policy
● delete-policy-version
● delete-thing ​(o)
● delete-topic-rule
● describe-certificate
● describe-endpoint
● describe-thing​ ​(o)
● detach-principal-policy
● detach-thing-principal
● disable-topic-rule
● enable-topic-rule
● get-logging-options
● get-policy
● get-policy-version
● get-topic-rule
● list-certificates ​(o)
● list-policies
● list-policy-versions
● list-principal-policies
● list-principal-things
● list-thing-principals
● list-things ​(o)
● list-topic-rules
● reject-certificate-transfer
● replace-topic-rule
● set-default-policy-version
● set-logging-options
● transfer-certificate
● update-certificate
● update-thing ​(o)
1. 安裝AWS CLI
Install & Upgrade the AWS CLI Using pip (Linkit 7688 已內建pip)
$ ​sudo pip install awscli
$ ​sudo pip install --upgrade awscli
2. 設定AWS config (需先在AWS IAM建立使用者,並取得access key和secret key)
Setting AWS CLI config
$ ​aws configure
AWS Access Key ID [None]: ​AKIAJFDZY6CZ3OODZDIQ
AWS Secret Access Key [None]:​gSZPpyP5YdmqDEeqkjpKWnSbYOeaDmADVV7o4AdA
Default region name [None]: ​us-west-2
Default output format [None]: ​json
3. 操作Thing
操作 Thing
【列出所有的thing】
$ ​aws iot list-things
[--next-token <value> ex: ”sadfkjigrfhweuhfhewfdh”]
[--max-results <value> ex: 10 ( value > 0 )]
[--attribute-name <value> ex: “attr1” 測試無法過濾多組條件]
[--attribute-value <value> ex: “111” 測試無法過濾多組條件]
[​--cli-input-json​ <value> ex: ​file://檔案路徑​,如file://commands.json]
[​--generate-cli-skeleton​ 用來顯示輸入JSON檔的格式 ex: 可為空值則將json顯示在畫面上,也
可將json寫進檔案,指令後面加上 ​> commands.json​ 即可]
綠字的兩組參數每個指令都有,使用方法也都一樣,後續不再贅述
【取得特定thing的資料】
$ ​aws iot-data describe-thing --thing-name ​<value>
【建立thing】
$ aws iot create-thing --thing-name ​<value>
[--attribute-payload <value> ex: attributes={KeyName1=string,KeyName2=string}]
【更新thing】
$ aws iot update-thing --thing-name ​<value> ​--attribute-payload ​<value>
[--attribute-payload <value> ex: attributes={KeyName1=string,KeyName2=string}]
【刪除thing】
$ aws iot delete-thing --thing-name ​<value>
4. 操作 Policy & 綁定 Policy < --- > Certificate
Create and Attach an AWS IoT Policy to Your Certificate
【Provision a Certificate】
$ aws iot create-keys-and-certificate --set-as-active
--certificate-pem-outfile ​cert.pem​ --public-key-outfile ​publicKey.pem
--private-key-outfile ​privateKey.pem
*把certificateArn記下來! 或是輸入 aws iot list-certificates來查詢
[--set-as-active | --no-set-as-active ex: 是否啟用憑證]
[--certificate-pem-outfile <value> ex: cert檔名]
[--public-key-outfile <value> ex: publicKey檔名]
[--private-key-outfile <value> ex: privateKey檔名]
【Creates an AWS IoT policy】
$ aws iot create-policy --policy-name ​<value>​ --policy-document
<file://path-to-your-policy-document>
[policy-document 含空白字元長度不可超過2048字元 example:
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:[​"iot:*"​],
​"Resource"​:​ ​[​"*"​]
​}]
}
]
【Attach the policy to your certificate】
$ aws iot attach-principal-policy --principal
arn:aws:iot:ap-northeast-1:000011112222:cert/773415c2aa56da4e07549cf0
1e0c3bf8cc6d2fc522388f29bff4bc032bfc4238​ --policy-name ​<value>
[--principal <value> ex: “certificate-arn”或是”cognito-id”]
5. 綁定 Thing < --- > Certificate
Attach your Certificate to Your Device
【Attach your Certificate to Your Device】
$ aws iot attach-thing-principal --thing-name ​<value>​ --principal
arn:aws:iot:ap-northeast-1:000011112222:cert/773415c2aa56da4e07549cf0
1e0c3bf8cc6d2fc522388f29bff4bc032bfc4238
6. Create an IAM Role for AWS IoT
【Create an IAM Role for AWS IoT】
$ aws iam create-role --role-name ​<value>
--assume-role-policy-document ​<file://path-to-your-policy-document>
Assume Role policy document.json example
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Sid"​:​ ​""​,
​"Effect"​:​ ​"Allow"​,
​"Principal"​:​ ​{
​"Service"​:​ ​"iot.amazonaws.com"
​},
​"Action"​:​ ​"sts:AssumeRole"
​}]
}
【Grant Permissions to the Role】
【Create IAM policy】
$ aws iam create-policy --policy-name ​<value>​ --policy-document
<file://IAM-policy-document-file-path>
*把Arn記下來! 或是輸入 aws iam list-roles來查詢
IAM policy document.json example Action部份依照需求調整
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​ ​"dynamodb:*"​,​ ​"lambda:InvokeFunction"​,​ ​"iot:Publish"​],
​"Resource"​:​ ​[​"*"​]
​}]
}
【Attach IAM policy】
$ ​aws iam attach-role-policy --role-name ​<value>​ --policy-arn
arn:aws:iam::964391593426:role/iot-actions-role
*可輸入 aws iam list-roles來查詢各個Role的Arn
【其他Service Role新增方式請參考以下連結】
http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/config-and-test-rules.html
7. Create Rule
To create a rule (AWS CLI)
【Create a Rule】
$ aws iot create-topic-rule --rule-name ​<value>​ --topic-rule-payload
<file://Rule-file-path>
REPUBLISH rule document.json example
{
​"sql"​:​ ​"SELECT * FROM ‘iot/test’"​,
​"ruleDisabled"​:​ ​false​,
​"actions"​:​ ​[{
​"republish"​:​ ​{
​"topic"​:​ ​"another/topic"​,
​"roleArn"​:​ ​"arn:aws:iam::964391593426:role/iot-actions-role"
​}
​}]
}
【其他AWS IoT範例請參考以下連結】
http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/aws-iot-rule-actions.html
【Viewing Your Rules】
$ aws iot list-topic-rules
$ aws iot get-topic-rule --rule-name ​<value>
【Deleting a Rule】
$ aws iot delete-topic-rule --rule-name ​<value>
【AWS IoT SQL Reference】
關於其他SQL指令用法如select, from, where或是function()請參考以下連結
http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/aws-iot-sql-reference.html
8. Device Shadows for AWS IoT (MQTT)
Device Shadows
Device Shadow是用來取回/儲存當前狀態的JSON檔案,開發者可以經由 MQTT/HTTP 取得與設定裝置
參數,Shadow是使用保留的MQTT topics來讓Applications和裝置(Device)可以進行
GET/UPDATE/DELETE等功能。
【Device Shadow Document Example】
{
​"state"​ ​:​ ​{
​"desired"​ ​:​ ​{ ​//​ Applications將欲更新的狀態寫到desired,而不是直接跟device連結
​"color"​ ​:​ ​"RED"​,
​"sequence"​ ​:​ ​[​ ​"RED"​,​ ​"GREEN"​,​ ​"BLUE"​ ​]
​},
​"reported"​ ​:​ ​{ ​//​ 裝置(Device)將當前的狀態寫到reported,Applications便可從reported取得裝置
(Device)狀態,而不需直接與裝置(Device)連結
​"color"​ ​:​ ​"GREEN"
​}
​},
​"metadata"​ ​:​ ​{ ​//用來存放裝置metadata,並紀錄資料異動的時間
​"desired"​ ​:​ ​{
​"color"​ ​:​ ​{
​"timestamp"​ ​:​ ​12345
​},
​"sequence"​ ​:​ ​{
​"timestamp"​ ​:​ ​12345
​}
​},
​"reported"​ ​:​ ​{
​"color"​ ​:​ ​{
​"timestamp"​ ​:​ ​12345
​}
​}
​},
​"version"​ ​:​ ​10​, ​//表示document version,每次更新shadow就+1
​"clientToken"​ ​:​ ​"UniqueClientToken"​, ​//一串unique string,用來確認MQTT req/res是否有相關
​"timestamp"​:​ ​123456789 ​//表示訊息在什麼時間點透過AWS IoT傳送
}
【Device Shadow MQTT Pub/Sub Messages】
保留的MQTT topics命名規則為​$aws/things/​thingName​/shadow + Messages(如下)
Messages
● /update
● /update/accepted
● /update/rejected
● /update/delta
● /get
● /get/accepted
● /get/rejected
● /delete
● /delete/accepted
● /delete/rejected
【Request State Documents】
{
​"state"​:​ ​{
​"desired"​:​ ​{
​"attribute1"​:​ integer2​,
​"attribute2"​:​ ​"string2"​,
​...
​"attributeN"​:​ boolean2
​},
​"reported"​:​ ​{
​"attribute1"​:​ integer1​,
​"attribute2"​:​ ​"string1"​,
​...
​"attributeN"​:​ boolean1
​}
​}
​"clientToken"​:​ ​"token"​,
​"version"​:​ version
}
【Response State Documents】
{
​"state"​:​ ​{
​"desired"​:​ ​{
​"attribute1"​:​ integer2​,
​"attribute2"​:​ ​"string2"​,
​...
​"attributeN"​:​ boolean2
​},
​"reported"​:​ ​{
​"attribute1"​:​ integer1​,
​"attribute2"​:​ ​"string1"​,
​...
​"attributeN"​:​ boolean1
​},
​"delta"​:​ ​{
​"attribute3"​:​ integerX​,
​"attribute5"​:​ ​"stringY"
​}
​},
​"metadata"​:​ ​{
​"desired"​:​ ​{
​"attribute1"​:​ ​{
​"timestamp"​:​ timestamp
​},
​"attribute2"​:​ ​{
​"timestamp"​:​ timestamp
​},
​...
​"attributeN"​:​ ​{
​"timestamp"​:​ timestamp
​}
​},
​"reported"​:​ ​{
​"attribute1"​:​ ​{
​"timestamp"​:​ timestamp
​},
​"attribute2"​:​ ​{
​"timestamp"​:​ timestamp
​},
​...
​"attributeN"​:​ ​{
​"timestamp"​:​ timestamp
​}
​}
​},
​"timestamp"​:​ timestamp​,
​"clientToken"​:​ ​"token"​,
​"version"​:​ version
}
【Error Response Documents】
{
​"code"​:​ error​-​code​,
​"message"​:​ ​"error-message"​,
​"timestamp"​:​ timestamp​,
​"clientToken"​:​ ​"token"
}
【MQTT Pub/Sub Messages】
/update 
publish到該topic,用來更新 thing shadow 
$aws/things/​thingName​/shadow/update 
AWS IoT responds by publishing to either​ ​/update/accepted​ or ​/update/rejected
Example Policy
The following is an example policy:
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Publish"​],
​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/update"​]
​}]
}
/update/accepted
當AWS IoT接收到 thing shadow有更新時會response state document到該topic
$aws/things/​thingName​/shadow/update/accepted
Example Policy 
The following is an example policy: 
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/update/accepted"​]
​}]
}
/update/rejected
當 AWS IoT拒絕 thing shadow 更新時會 response error document 到該 topic
$aws/things/​thingName​/shadow/update/rejected
Example Policy 
The following is an example policy: 
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/update/rejected"​]
​}]
}
/update/delta
當AWS IoT接收到 thing shadow有更新時,​且 desired state 與 reported state 不一致​時會response
state document到該topic
$aws/things/​thingName​/shadow/update/delta
Example Policy 
The following is an example policy: 
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/update/delta"​]
​}]
}
/get 
publish到該topic,用來取得 thing shadow 
$aws/things/​thingName​/shadow/get 
AWS IoT responds by publishing to either ​/get/accepted​ ​or​ ​/get/rejected​.
Example Policy
The following is an example policy:
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Publish"​],
​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/get"​]
​}]
}
/get/accepted 
當 AWS IoT接收到 thing shadow /get 時會 response state document 到該topic 
$aws/things/​thingName​/shadow/get/accepted 
Example Policy
The following is an example policy:
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/get/accepted"​]
​}]
}
/get/rejected 
當 AWS IoT 無法 return thing shadow 時會 response error document 到該 topic 
$aws/things/​thingName​/shadow/get/rejected 
Example Policy
The following is an example policy:
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/get/rejected"​]
​}]
}
/delete
publish到該topic,用來刪除 thing shadow,訊息內容( Request state document )可忽略
$aws/things/​thingName​/shadow/delete
AWS IoT responds by publishing to either ​/delete/accepted​ or ​/delete/rejected​.
Example Policy 
The following is an example policy: 
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/delete"​]
​}]
}
 
/delete/accepted 
當 AWS IoT 接收到 thing shadow /delete 時會 response state document 到該topic 
$aws/things/​thingName​/shadow/delete/accepted 
Example Policy
The following is an example policy:
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/delete/accepted"​]
​}]
}
/delete/rejected 
當 AWS IoT 無法刪除 thing shadow 時會 response error document 到該 topic 
$ aws/things/​thingName​/shadow/delete/rejected 
Example Policy
The following is an example policy:
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​"iot:Subscribe"​],
​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/delete/rejected"​]
​}]
}
【Demo】
模擬裝置 Update "reported”
$ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state":
{"reported" : {"power" : "on"}}}'​ ​outfile.json
模擬手機App Update "desired”
$ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state":
{"desired" : {"power" : "off"}}}'​ ​outfile2.json
模擬取得 Shadow Thing "delta”
$ aws iot-data get-thing-shadow --thing-name ​<value>​ ​outfile3.json
可取得”​delta​”區塊的資料,表示”reported”和”desired”資料不同步
{
"state"​:​ ​{
​"desired"​:​ ​{
​"power"​:​ ​"on"
​},
​"reported"​:​ ​{
​"power"​:​ ​"off"
​},
​"delta": {
"power": "on"
}
}
}
模擬同步 Shadow Thing "delta”
$ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state":
{"reported" : {"power" : "on"}}}'​ ​outfile4.json
模擬再次取得 Shadow Thing "delta”
$ aws iot-data get-thing-shadow --thing-name ​<value>​ ​outfile5.json
可發現”reported”和”desired”區塊的資料已同步完成
{
"state"​:​ ​{
​"desired"​:​ ​{
​"power"​:​ ​"on"
​},
​"reported"​:​ ​{
​"power"​:​ ​"​on​"
​}​,
"delta": {
"power": "on"
}
}
}
模擬 Version conflict
$ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state":
{"reported" : {"power" : "on"}}, “version” : 1}'​ ​outfile6.json
會出現錯誤訊息 ​A client error (ConflictException) occurred when calling the
UpdateThingShadow operation: ​Version conflict
【MQTT Pub/Sub Messages】
HTTP Error Code Error Messages
400 (Bad Request) ● Invalid JSON
● Missing required node: state
● State node must be an object
● Desired node must be an object
● Reported node must be an object
● Invalid version
● Invalid clientToken
● JSON contains too many levels of
nesting; maximum is 6
● State contains an invalid node
401 (Unauthorized) ● Unauthorized
403 (Forbidden) ● Forbidden
404 (Not Found) ● Thing not found
409 (Conflict) ● Version conflict
413 (Payload Too Large) ● The payload exceeds the maximum size
allowed
415 (Unsupported Media Type) ● Unsupported documented encoding;
supported encoding is UTF-8
500 (Internal Server Error) ● Internal service failure
9. AWS IoT SDK ( Node.js )
安裝 AWS IoT SDK - 以 Raspberry Pi 為例 ( Linkit 7688 也適用)
官方詳細安裝步驟
Install the AWS IoT Device SDK for Node.js & Example
https://github.com/aws/aws-iot-device-sdk-js
$ npm install aws-iot-device-sdk
Download root-CA
Download ​root-CA
$ curl -o ​root-CA.crt​ https://www.symantec.com/cont
ent/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primar
y-Certificatio n-Authority-G5.pem
【Provision a Certificate】
$ aws iot create-keys-and-certificate --set-as-active
--certificate-pem-outfile ​cert.pem​ --public-key-outfile
publicKey.pem​ --private-key-outfile ​privateKey.pem
Get endpoint
$ aws iot describe-endpoint
Examples
【Device class】
awsIot.device(option),option也可以是mqtt.js支援的參數
https://github.com/mqttjs/MQTT.js/blob/master/README.md#client
var​ awsIot ​=​ ​require​(​'aws-iot-device-sdk'​);
var​ device ​=​ awsIot.​device​({
keyPath​:​ ​'~/awsCerts/private.pem.key'​,
certPath​:​ ​'~/awsCerts/certificate.pem.crt'​,
caPath​:​ ​'~/awsCerts/root-CA.crt'​,
clientId​:​ ​'myAwsClientId'​,
region​:​ ​'us-east-1'
});
//
// Device is an instance returned by mqtt.Client(), see mqtt.js for full
// documentation.
//
device
.​on​(​'connect'​, ​function​() {
​console​.​log​(​'connect'​);
device.​subscribe​(​'topic_1'​);
device.​publish​(​'topic_2'​, ​JSON​.​stringify​({ test_data​:​ ​1​}));
});
device
.​on​(​'message'​, ​function​(topic, payload) {
​console​.​log​(​'message'​, topic, payload.​toString​());
});
10. AWS IoT Troubleshooting
AWS IoT Troubleshooting
1. The thing shadow supports 8 KB of data only.
2. 建立 AWS CloudWatch 來查看 AWS IoT Logging
https://ap-northeast-1.console.aws.amazon.com/cloudwatch/home?region=ap-northeast-1
#logs:
【Create an IAM Role for AWS IoT】
$ aws iam create-role --role-name ​<value>
--assume-role-policy-document ​<file://path-to-your-policy-document>
Assume Logging Role policy document.json example
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[
​{
​"Sid"​:​ ​""​,
​"Effect"​:​ ​"Allow"​,
​"Principal"​:​ ​{
​"Service"​:​ ​"iot.amazonaws.com"
​},
​"Action"​:​ ​"sts:AssumeRole"
​}
​]
}
【Grant Permissions to the Role】
【Create IAM policy】
該步驟可省略,IAM已經有內建的 CloudWatch 相關的 Policy 可直接使用,透過指令來查
詢有哪些可用的Policy
$ aws iam list-policies | grep CloudWatch
$ aws iam create-policy --policy-name ​<value>​ --policy-document
<file://IAM-policy-document-file-path>
*把Arn記下來! 或是輸入 aws iam list-roles來查詢
IAM policy document.json example Action部份依照需求調整
{
​"Version"​:​ ​"2012-10-17"​,
​"Statement"​:​ ​[{
​"Effect"​:​ ​"Allow"​,
​"Action"​:​ ​[​ ​"dynamodb:*"​,​ ​"lambda:InvokeFunction"​,​ ​"iot:Publish"​],
​"Resource"​:​ ​[​"*"​]
​}]
}
【Attach IAM policy】
$ ​aws iam attach-role-policy --role-name ​<value>​ --policy-arn
arn:aws:iam::964391593426:role/iot-actions-role
*可輸入 aws iam list-roles來查詢各個Role的Arn
【Register the Logging Role with AWS IoT】
$ aws iot set-logging-options --logging-options-payload
roleArn="arn:aws:iam::​<your-aws-account-num>​:​role/IoTLoggingRole​",log
Level="​INFO​"
更多關於 AWS CloudWatch 的設定請參閱以下連結:
http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/cloud-watc
h-logs.html
11. AWS IoT Limits
AWS IoT Limits
Topic length limit 256 bytes encoded in UTF-8.
Restricted topic prefix Topics開頭’​$​’是保留字,除了 Thing
Shadows 外都不可使用
Maximum number of slashes in topic and
topic filter
最多8個 slashes (/)
Client ID size limit 128 bytes encoded in UTF-8.
Restricted client ID prefix ’​$​’ 是 client IDs 保留字
Message size limit payload 最多 128 KB,若超過大小會被
AWS IoT Service reject
Throughput per connection AWS IoT limits the ingress and egress rate
on each client connection to 512 KB/s. Data
sent or received at a higher rate will be
throttled to this throughput.
Maximum subscriptions per subscribe call A single subscribe call is limited to request
a maximum of eight subscriptions.
Subscriptions per session The message broker limits each client
session to subscribe to up to 50
subscriptions. A subscribe request that
pushes the total number of subscriptions
past 50 will result in the connection being
disconnected.
Connection inactivity (keep-alive) limits 預設30秒沒有任何動作則斷開連結,也可設
定更短的keep-alive,範圍5~1200秒,設定
<5秒則以5秒為預設;設定0秒則以預設值執
行
Maximum inbound unacknowledged
messages
The message broker allows 100 in-flight
unacknowledged messages (limit is across
all messages requiring ACK). When this
limit is reached, no new messages will be
accepted until an ACK is returned by the
server.
Maximum outbound unacknowledged
messages
The message broker only allows 100
in-flight unacknowledged messages (limit is
across all messages requiring ACK). When
this limit is reached, no new messages will
be sent to the client until the client
acknowledges the in-flight messages.
Maximum retry interval for delivering QoS 1
messages
If a connected client is unable to receive an
ACK on a QoS 1 message for one hour, the
message broker will drop the message. The
client may be unable to receive the
message if it has 100 in-flight messages, it
is being throttled due to large payloads, or
other errors.
WebSocket connection duration WebSocket連線限制為5分鐘,超過則會斷
線,若要連線超過5分鐘,則在 client 端關閉
連線並重開即可
AWS IoT Rule Engine 與 AWS Lambda結合
1. 在​AWS Lambda​建立測試用的Function,也可用CLI產出Rule,語法如下:
產出Rule
$ aws iot create-topic-rule --rule-name my-rule-name --topic-rule-payload
file://my-rule.json-path
// my-rule.json
{
​"sql"​:​ ​"expression"​,
​"ruleDisabled"​:​ ​false​,
​"actions"​:​ ​[{
​"lambda"​:​ ​{
​"functionArn"​:​ ​"arn:aws:lambda:us-west-2:123456789012:function:my-lambda-function"
​}
​}]
}
2. 在AWS IoT建立Rule,觸發Rule後將payload轉送到Lambda Function
3. 使用MQTTfx發送會觸發Rule的payload
{
​"key1"​:​"111",
​"key2"​:​"222",
​"key3"​:​"333"
}
4. 在​AWS CloudWatch​查看Lambda Log,就可以看到觸發Rule後所轉送過來的資料
Demo1: 展示直接連結Device
node /root/project/aws/device.js
MQTTfx: subscribe “test2”
MQTTfx: publish “test1”
Demo2: 用Demo1展示Rule engine
Rule Engine設置republish to "rep/test”
Demo3: 展示透過shadow thing來溝通而不是直接連結裝置
接收端(led燈): node /root/project/aws/shadowThing.js
發送端:node /root/project/aws2/thing-passthrough-example.js --test-mode=1
用MQTTfx來觀看實際註冊情形,先subscribe以下幾組:
http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/thing-shadow-data-flow.html
$aws/things/myLightBulb/shadow/update/accepted 
The Thing Shadows service sends messages to this topic when an update is 
successfully made to a thing shadow. 
$aws/things/myLightBulb/shadow/update/rejected 
The Thing Shadows service sends messages to this topic when an update to a 
thing shadow is rejected. 
$aws/things/myLightBulb/shadow/update/delta 
The Thing Shadows service sends messages to this topic when a difference is 
detected between the reported and desired sections of a thing shadow. 
$aws/things/myLightBulb/shadow/get/accepted 
The Thing Shadows service sends messages to this topic when a request for a 
thing shadow is made successfully. 
$aws/things/myLightBulb/shadow/get/rejected 
The Thing Shadows service sends messages to this topic when a request for a 
thing shadow is rejected. 

More Related Content

What's hot

AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)Amazon Web Services Korea
 
Best Practices for IoT Security in the Cloud
Best Practices for IoT Security in the CloudBest Practices for IoT Security in the Cloud
Best Practices for IoT Security in the CloudAmazon Web Services
 
Webinar - AWS 201 IoT with AWS - Smart devices powered by the cloud
Webinar - AWS 201 IoT with AWS - Smart devices powered by the cloudWebinar - AWS 201 IoT with AWS - Smart devices powered by the cloud
Webinar - AWS 201 IoT with AWS - Smart devices powered by the cloudAmazon Web Services
 
Reply Webinar Online - Mastering AWS - IoT Advanced
Reply Webinar Online - Mastering AWS - IoT AdvancedReply Webinar Online - Mastering AWS - IoT Advanced
Reply Webinar Online - Mastering AWS - IoT AdvancedAndrea Mercanti
 
(MBL205) New! Everything You Want to Know About AWS IoT
(MBL205) New! Everything You Want to Know About AWS IoT(MBL205) New! Everything You Want to Know About AWS IoT
(MBL205) New! Everything You Want to Know About AWS IoTAmazon Web Services
 
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)Amazon Web Services Korea
 
Building Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisBuilding Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisFIWARE
 
AWS Re:Invent - Securing HIPAA Compliant Apps in AWS
AWS Re:Invent - Securing HIPAA Compliant Apps in AWSAWS Re:Invent - Securing HIPAA Compliant Apps in AWS
AWS Re:Invent - Securing HIPAA Compliant Apps in AWSControl Group
 
Aptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloud
Aptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloudAptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloud
Aptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloudAptible
 
Building IAM for OpenStack
Building IAM for OpenStackBuilding IAM for OpenStack
Building IAM for OpenStackSteve Martinelli
 
Intro to the FIWARE Lab
Intro to the FIWARE LabIntro to the FIWARE Lab
Intro to the FIWARE LabFIWARE
 
Chef and Apache CloudStack (ChefConf 2014)
Chef and Apache CloudStack (ChefConf 2014)Chef and Apache CloudStack (ChefConf 2014)
Chef and Apache CloudStack (ChefConf 2014)Jeff Moody
 
Cloud computing, SaaS, and security
Cloud computing, SaaS, and securityCloud computing, SaaS, and security
Cloud computing, SaaS, and securityMichael Van Kleeck
 
Reply Webinar Online - Mastering AWS - DB as a Service
Reply Webinar Online - Mastering AWS - DB as a ServiceReply Webinar Online - Mastering AWS - DB as a Service
Reply Webinar Online - Mastering AWS - DB as a ServiceAndrea Mercanti
 
Best Practices of IoT Security in the Cloud
Best Practices of IoT Security in the CloudBest Practices of IoT Security in the Cloud
Best Practices of IoT Security in the CloudAmazon Web Services
 
Deep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons LearnedDeep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons LearnedPriti Desai
 
Hands-on Lab: Comparing Redis with Relational
Hands-on Lab: Comparing Redis with RelationalHands-on Lab: Comparing Redis with Relational
Hands-on Lab: Comparing Redis with RelationalAmazon Web Services
 
Hands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with RelationalHands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with RelationalAmazon Web Services
 
How to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkHow to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkZend by Rogue Wave Software
 

What's hot (20)

AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
 
Best Practices for IoT Security in the Cloud
Best Practices for IoT Security in the CloudBest Practices for IoT Security in the Cloud
Best Practices for IoT Security in the Cloud
 
Webinar - AWS 201 IoT with AWS - Smart devices powered by the cloud
Webinar - AWS 201 IoT with AWS - Smart devices powered by the cloudWebinar - AWS 201 IoT with AWS - Smart devices powered by the cloud
Webinar - AWS 201 IoT with AWS - Smart devices powered by the cloud
 
Reply Webinar Online - Mastering AWS - IoT Advanced
Reply Webinar Online - Mastering AWS - IoT AdvancedReply Webinar Online - Mastering AWS - IoT Advanced
Reply Webinar Online - Mastering AWS - IoT Advanced
 
(MBL205) New! Everything You Want to Know About AWS IoT
(MBL205) New! Everything You Want to Know About AWS IoT(MBL205) New! Everything You Want to Know About AWS IoT
(MBL205) New! Everything You Want to Know About AWS IoT
 
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)
 
Building Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisBuilding Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEis
 
AWS Re:Invent - Securing HIPAA Compliant Apps in AWS
AWS Re:Invent - Securing HIPAA Compliant Apps in AWSAWS Re:Invent - Securing HIPAA Compliant Apps in AWS
AWS Re:Invent - Securing HIPAA Compliant Apps in AWS
 
Getting Started with AWS IoT
Getting Started with AWS IoTGetting Started with AWS IoT
Getting Started with AWS IoT
 
Aptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloud
Aptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloudAptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloud
Aptible, AWS, and Telepharm: Architecting HIPAA compliance for the cloud
 
Building IAM for OpenStack
Building IAM for OpenStackBuilding IAM for OpenStack
Building IAM for OpenStack
 
Intro to the FIWARE Lab
Intro to the FIWARE LabIntro to the FIWARE Lab
Intro to the FIWARE Lab
 
Chef and Apache CloudStack (ChefConf 2014)
Chef and Apache CloudStack (ChefConf 2014)Chef and Apache CloudStack (ChefConf 2014)
Chef and Apache CloudStack (ChefConf 2014)
 
Cloud computing, SaaS, and security
Cloud computing, SaaS, and securityCloud computing, SaaS, and security
Cloud computing, SaaS, and security
 
Reply Webinar Online - Mastering AWS - DB as a Service
Reply Webinar Online - Mastering AWS - DB as a ServiceReply Webinar Online - Mastering AWS - DB as a Service
Reply Webinar Online - Mastering AWS - DB as a Service
 
Best Practices of IoT Security in the Cloud
Best Practices of IoT Security in the CloudBest Practices of IoT Security in the Cloud
Best Practices of IoT Security in the Cloud
 
Deep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons LearnedDeep Dive into Keystone Tokens and Lessons Learned
Deep Dive into Keystone Tokens and Lessons Learned
 
Hands-on Lab: Comparing Redis with Relational
Hands-on Lab: Comparing Redis with RelationalHands-on Lab: Comparing Redis with Relational
Hands-on Lab: Comparing Redis with Relational
 
Hands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with RelationalHands-on Lab - Combaring Redis with Relational
Hands-on Lab - Combaring Redis with Relational
 
How to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkHow to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend Framework
 

Similar to Notes for AWS IoT

AWS Cyber Security Best Practices
AWS Cyber Security Best PracticesAWS Cyber Security Best Practices
AWS Cyber Security Best PracticesDoiT International
 
AWS October Webinar Series - Getting Started with AWS IoT
AWS October Webinar Series - Getting Started with AWS IoTAWS October Webinar Series - Getting Started with AWS IoT
AWS October Webinar Series - Getting Started with AWS IoTAmazon Web Services
 
Python in the serverless era (PyCon 2017)
Python in the serverless era (PyCon 2017)Python in the serverless era (PyCon 2017)
Python in the serverless era (PyCon 2017)Benny Bauer
 
Hands-on with AWS IoT
Hands-on with AWS IoTHands-on with AWS IoT
Hands-on with AWS IoTJulien SIMON
 
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksEssential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksAmazon Web Services
 
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...Amazon Web Services
 
(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & Rules
(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & Rules(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & Rules
(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & RulesAmazon Web Services
 
Best Practices of IoT in the Cloud
Best Practices of IoT in the CloudBest Practices of IoT in the Cloud
Best Practices of IoT in the CloudAmazon Web Services
 
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using ThingsAmazon Web Services
 
Best Practices for IoT Security in the Cloud
Best Practices for IoT Security in the CloudBest Practices for IoT Security in the Cloud
Best Practices for IoT Security in the CloudAmazon Web Services
 
Hands-on with AWS IoT (November 2016)
Hands-on with AWS IoT (November 2016)Hands-on with AWS IoT (November 2016)
Hands-on with AWS IoT (November 2016)Julien SIMON
 
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)Amazon Web Services
 
Cloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWSCloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWSAmine Sadry
 
以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界Amazon Web Services
 
February 2016 Webinar Series - Best Practices for IoT Security in the Cloud
February 2016 Webinar Series - Best Practices for IoT Security in the CloudFebruary 2016 Webinar Series - Best Practices for IoT Security in the Cloud
February 2016 Webinar Series - Best Practices for IoT Security in the CloudAmazon Web Services
 
Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...
Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...
Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...Amazon Web Services
 
서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)
서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)
서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)Amazon Web Services Korea
 

Similar to Notes for AWS IoT (20)

AWS Cyber Security Best Practices
AWS Cyber Security Best PracticesAWS Cyber Security Best Practices
AWS Cyber Security Best Practices
 
AWS October Webinar Series - Getting Started with AWS IoT
AWS October Webinar Series - Getting Started with AWS IoTAWS October Webinar Series - Getting Started with AWS IoT
AWS October Webinar Series - Getting Started with AWS IoT
 
AWS IoT Deep Dive
AWS IoT Deep DiveAWS IoT Deep Dive
AWS IoT Deep Dive
 
Python in the serverless era (PyCon 2017)
Python in the serverless era (PyCon 2017)Python in the serverless era (PyCon 2017)
Python in the serverless era (PyCon 2017)
 
Hands-on with AWS IoT
Hands-on with AWS IoTHands-on with AWS IoT
Hands-on with AWS IoT
 
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksEssential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
 
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
 
(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & Rules
(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & Rules(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & Rules
(MBL312) NEW! AWS IoT: Programming a Physical World w/ Shadows & Rules
 
Ansible Automation - Enterprise Use Cases | Juncheng Anthony Lin
Ansible Automation - Enterprise Use Cases | Juncheng Anthony LinAnsible Automation - Enterprise Use Cases | Juncheng Anthony Lin
Ansible Automation - Enterprise Use Cases | Juncheng Anthony Lin
 
Best Practices of IoT in the Cloud
Best Practices of IoT in the CloudBest Practices of IoT in the Cloud
Best Practices of IoT in the Cloud
 
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
 
Best Practices for IoT Security in the Cloud
Best Practices for IoT Security in the CloudBest Practices for IoT Security in the Cloud
Best Practices for IoT Security in the Cloud
 
Hands-on with AWS IoT (November 2016)
Hands-on with AWS IoT (November 2016)Hands-on with AWS IoT (November 2016)
Hands-on with AWS IoT (November 2016)
 
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
 
Cloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWSCloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWS
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
 
以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界
 
February 2016 Webinar Series - Best Practices for IoT Security in the Cloud
February 2016 Webinar Series - Best Practices for IoT Security in the CloudFebruary 2016 Webinar Series - Best Practices for IoT Security in the Cloud
February 2016 Webinar Series - Best Practices for IoT Security in the Cloud
 
Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...
Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...
Best Practices for Managing Security Operations in AWS - AWS July 2016 Webina...
 
서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)
서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)
서버리스 IoT 백엔드 개발 및 구현 사례 : 윤석찬 (AWS 테크에반젤리스트)
 

More from 承翰 蔡

Node-red Chatbot module
Node-red Chatbot moduleNode-red Chatbot module
Node-red Chatbot module承翰 蔡
 
Bitcoin developer guide
Bitcoin developer guideBitcoin developer guide
Bitcoin developer guide承翰 蔡
 
The 3rd generation blockchain
The 3rd generation blockchainThe 3rd generation blockchain
The 3rd generation blockchain承翰 蔡
 
How to create ethereum token (A plan coin ico)
How to create ethereum token (A plan coin ico)How to create ethereum token (A plan coin ico)
How to create ethereum token (A plan coin ico)承翰 蔡
 
Web of things introduction
Web of things introductionWeb of things introduction
Web of things introduction承翰 蔡
 
IoT開發平台NodeMCU
IoT開發平台NodeMCUIoT開發平台NodeMCU
IoT開發平台NodeMCU承翰 蔡
 
Node mcu x raspberrypi2 x mqtt
Node mcu x raspberrypi2 x mqttNode mcu x raspberrypi2 x mqtt
Node mcu x raspberrypi2 x mqtt承翰 蔡
 
Arduino mqtt client introduction
Arduino mqtt client introductionArduino mqtt client introduction
Arduino mqtt client introduction承翰 蔡
 
Webduino introduction
Webduino introductionWebduino introduction
Webduino introduction承翰 蔡
 
MongoDB 3.0.0 vs 2.6.x vs 2.4.x Benchmark
MongoDB 3.0.0 vs 2.6.x vs 2.4.x BenchmarkMongoDB 3.0.0 vs 2.6.x vs 2.4.x Benchmark
MongoDB 3.0.0 vs 2.6.x vs 2.4.x Benchmark承翰 蔡
 
Kimono sharing
Kimono sharingKimono sharing
Kimono sharing承翰 蔡
 

More from 承翰 蔡 (12)

Node-red Chatbot module
Node-red Chatbot moduleNode-red Chatbot module
Node-red Chatbot module
 
Ipfs
IpfsIpfs
Ipfs
 
Bitcoin developer guide
Bitcoin developer guideBitcoin developer guide
Bitcoin developer guide
 
The 3rd generation blockchain
The 3rd generation blockchainThe 3rd generation blockchain
The 3rd generation blockchain
 
How to create ethereum token (A plan coin ico)
How to create ethereum token (A plan coin ico)How to create ethereum token (A plan coin ico)
How to create ethereum token (A plan coin ico)
 
Web of things introduction
Web of things introductionWeb of things introduction
Web of things introduction
 
IoT開發平台NodeMCU
IoT開發平台NodeMCUIoT開發平台NodeMCU
IoT開發平台NodeMCU
 
Node mcu x raspberrypi2 x mqtt
Node mcu x raspberrypi2 x mqttNode mcu x raspberrypi2 x mqtt
Node mcu x raspberrypi2 x mqtt
 
Arduino mqtt client introduction
Arduino mqtt client introductionArduino mqtt client introduction
Arduino mqtt client introduction
 
Webduino introduction
Webduino introductionWebduino introduction
Webduino introduction
 
MongoDB 3.0.0 vs 2.6.x vs 2.4.x Benchmark
MongoDB 3.0.0 vs 2.6.x vs 2.4.x BenchmarkMongoDB 3.0.0 vs 2.6.x vs 2.4.x Benchmark
MongoDB 3.0.0 vs 2.6.x vs 2.4.x Benchmark
 
Kimono sharing
Kimono sharingKimono sharing
Kimono sharing
 

Recently uploaded

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 

Recently uploaded (20)

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 

Notes for AWS IoT

  • 1. AWS IoT主要功能 一、​Device gateway 遙控器與燈泡都透過MQTT與AWS IoT溝通,遙控器publish command、燈泡subscribe + listen command,把AWS IoT當作broker使用。 二、​Rules Engine AWS IoT收到publish過來的資料,做完資料轉換後再傳到有subscribe的裝置上。 三、​Rules actions Rule Engine除了可以控制傳進來的資訊,轉換後再傳給device,除此之外也可以傳給其他端 點,例如AWS Lambda functions 、 DynamoDB table 或是 Simple Notification Service (SNS) 讓通知訊息可以傳到手機端。
  • 3. 設定Rule Engine 1. 先設定​IAM​來管理使用者及存取權限 → Role → Create New Role → Attach Policy (選 擇AWSIoTRuleActions) → Finish 2. 接著設定該Role的Polity, Role → Inline Policies (Create one) → 選擇Policy Generator (若想自行寫json,可選擇Custom) → 照下圖,Service選擇Publish、ARN 填寫arn:aws:iot:​us-west-2​:​964391593426​:topic/{{topic}},就可以開啟Publish的權 限。 ​
  • 4. 3. 接著使用AWS IoT新增規則(Create a rule),填好要過濾的規則後並選擇【AWS IoT Republish】,再填寫要轉送的topic以及剛剛申請好的testRole。 最後再發送payload到my/topic,就會也轉送一份到/test,完成整個Rule。
  • 5. AWS IoT收費機制 AWS IoT Device SDK for Node.js CA certificate可直接從官網下載 *調整Authorization ===========名詞解釋============= Amazon Resource Name (ARN) 表示 AWS 內的資源,包含以冒號分隔的多個欄位: 最前兩節固定為 aws 與 arn 服務名稱,例如 iam, dynamodb region, 例如 ap-northeast-1, 某些服務可省略 account, 帳號號碼(一堆數字,不帶分隔符號),可省略
  • 6. resource identifier,依照各服務而有差異;可能是 *, aaaa, aaa/bbb, aaa:bbb 等格 式,在AWS IOT為Policy AWS Identity and Access Management (IAM) 管理 IAM 使用者​及​其存取權​ – 您可以在 IAM 中建立使用者,為他們指派個別的安全登入資料 (換 句話說,就是存取金鑰、密碼和​多重驗證​裝置),或請求臨時的安全登入資料,為使用者提供 AWS 服務和資源的存取權。您可以管理許可以控制使用者可執行的操作。 管理 IAM 角色​及其​許可​ – 您可以在 IAM 中建立角色和管理許可,以控制擔任該角色的實體或 AWS 服務可執行的操作。您也可以定義允許擔任該角色的實體。 管理聯合身分使用者​及其​許可​ – 您可以啟用聯合身分功能,以允許企業中的現有身分 (使用者、群 組和角色) 存取 AWS 管理主控台、呼叫 AWS API 以及存取資源,而不必為每個身分建立 IAM 使 用者。 =============================== 1. thingShadow class必須先register後才能進行操作,如get, update等 等。 2. state desired The desired state of the thing. Applications can write to this portion of the document to update the state of a thing without having to directly connect to a thing. reported The reported state of the thing. Things write to this portion of the document to report their new state. Applications read this portion of the document to determine the state
  • 7. of a thing. metadata Information about the data stored in the state section of the document. This includes timestamps, in Epoch time, for eac 3. 7688必須先安裝AWS CLI: pip install awscli 4. 建立Certificate相關檔案: ​aws iot create-keys-and-certificate --set-as-active --certificate-pem-outfile cert.pem --public-key-outfile publicKey.pem --private-key-outfile privateKey.pem 便會產出3個相關的檔案 5. 補充資料
  • 8. AWS CLI語法 Available Commands ● accept-certificate-transfer ● attach-principal-policy ​(o) ● attach-thing-principal ​(o) ● cancel-certificate-transfer ● create-certificate-from-csr ● create-keys-and-certificate ​(o) ● create-policy ​(o) ● create-policy-version ● create-thing ​(o) ● create-topic-rule ● delete-certificate ● delete-policy ● delete-policy-version ● delete-thing ​(o) ● delete-topic-rule ● describe-certificate ● describe-endpoint ● describe-thing​ ​(o) ● detach-principal-policy ● detach-thing-principal ● disable-topic-rule ● enable-topic-rule ● get-logging-options ● get-policy ● get-policy-version ● get-topic-rule ● list-certificates ​(o) ● list-policies ● list-policy-versions
  • 9. ● list-principal-policies ● list-principal-things ● list-thing-principals ● list-things ​(o) ● list-topic-rules ● reject-certificate-transfer ● replace-topic-rule ● set-default-policy-version ● set-logging-options ● transfer-certificate ● update-certificate ● update-thing ​(o) 1. 安裝AWS CLI Install & Upgrade the AWS CLI Using pip (Linkit 7688 已內建pip) $ ​sudo pip install awscli $ ​sudo pip install --upgrade awscli 2. 設定AWS config (需先在AWS IAM建立使用者,並取得access key和secret key) Setting AWS CLI config $ ​aws configure AWS Access Key ID [None]: ​AKIAJFDZY6CZ3OODZDIQ AWS Secret Access Key [None]:​gSZPpyP5YdmqDEeqkjpKWnSbYOeaDmADVV7o4AdA Default region name [None]: ​us-west-2 Default output format [None]: ​json 3. 操作Thing 操作 Thing 【列出所有的thing】 $ ​aws iot list-things [--next-token <value> ex: ”sadfkjigrfhweuhfhewfdh”] [--max-results <value> ex: 10 ( value > 0 )] [--attribute-name <value> ex: “attr1” 測試無法過濾多組條件] [--attribute-value <value> ex: “111” 測試無法過濾多組條件]
  • 10. [​--cli-input-json​ <value> ex: ​file://檔案路徑​,如file://commands.json] [​--generate-cli-skeleton​ 用來顯示輸入JSON檔的格式 ex: 可為空值則將json顯示在畫面上,也 可將json寫進檔案,指令後面加上 ​> commands.json​ 即可] 綠字的兩組參數每個指令都有,使用方法也都一樣,後續不再贅述 【取得特定thing的資料】 $ ​aws iot-data describe-thing --thing-name ​<value> 【建立thing】 $ aws iot create-thing --thing-name ​<value> [--attribute-payload <value> ex: attributes={KeyName1=string,KeyName2=string}] 【更新thing】 $ aws iot update-thing --thing-name ​<value> ​--attribute-payload ​<value> [--attribute-payload <value> ex: attributes={KeyName1=string,KeyName2=string}] 【刪除thing】 $ aws iot delete-thing --thing-name ​<value> 4. 操作 Policy & 綁定 Policy < --- > Certificate Create and Attach an AWS IoT Policy to Your Certificate 【Provision a Certificate】 $ aws iot create-keys-and-certificate --set-as-active --certificate-pem-outfile ​cert.pem​ --public-key-outfile ​publicKey.pem --private-key-outfile ​privateKey.pem *把certificateArn記下來! 或是輸入 aws iot list-certificates來查詢 [--set-as-active | --no-set-as-active ex: 是否啟用憑證] [--certificate-pem-outfile <value> ex: cert檔名] [--public-key-outfile <value> ex: publicKey檔名] [--private-key-outfile <value> ex: privateKey檔名] 【Creates an AWS IoT policy】 $ aws iot create-policy --policy-name ​<value>​ --policy-document <file://path-to-your-policy-document> [policy-document 含空白字元長度不可超過2048字元 example: { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:[​"iot:*"​], ​"Resource"​:​ ​[​"*"​]
  • 11. ​}] } ] 【Attach the policy to your certificate】 $ aws iot attach-principal-policy --principal arn:aws:iot:ap-northeast-1:000011112222:cert/773415c2aa56da4e07549cf0 1e0c3bf8cc6d2fc522388f29bff4bc032bfc4238​ --policy-name ​<value> [--principal <value> ex: “certificate-arn”或是”cognito-id”] 5. 綁定 Thing < --- > Certificate Attach your Certificate to Your Device 【Attach your Certificate to Your Device】 $ aws iot attach-thing-principal --thing-name ​<value>​ --principal arn:aws:iot:ap-northeast-1:000011112222:cert/773415c2aa56da4e07549cf0 1e0c3bf8cc6d2fc522388f29bff4bc032bfc4238 6. Create an IAM Role for AWS IoT 【Create an IAM Role for AWS IoT】 $ aws iam create-role --role-name ​<value> --assume-role-policy-document ​<file://path-to-your-policy-document> Assume Role policy document.json example { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Sid"​:​ ​""​, ​"Effect"​:​ ​"Allow"​, ​"Principal"​:​ ​{ ​"Service"​:​ ​"iot.amazonaws.com" ​}, ​"Action"​:​ ​"sts:AssumeRole" ​}] } 【Grant Permissions to the Role】 【Create IAM policy】 $ aws iam create-policy --policy-name ​<value>​ --policy-document <file://IAM-policy-document-file-path> *把Arn記下來! 或是輸入 aws iam list-roles來查詢 IAM policy document.json example Action部份依照需求調整 { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​ ​"dynamodb:*"​,​ ​"lambda:InvokeFunction"​,​ ​"iot:Publish"​], ​"Resource"​:​ ​[​"*"​] ​}] }
  • 12. 【Attach IAM policy】 $ ​aws iam attach-role-policy --role-name ​<value>​ --policy-arn arn:aws:iam::964391593426:role/iot-actions-role *可輸入 aws iam list-roles來查詢各個Role的Arn 【其他Service Role新增方式請參考以下連結】 http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/config-and-test-rules.html 7. Create Rule To create a rule (AWS CLI) 【Create a Rule】 $ aws iot create-topic-rule --rule-name ​<value>​ --topic-rule-payload <file://Rule-file-path> REPUBLISH rule document.json example { ​"sql"​:​ ​"SELECT * FROM ‘iot/test’"​, ​"ruleDisabled"​:​ ​false​, ​"actions"​:​ ​[{ ​"republish"​:​ ​{ ​"topic"​:​ ​"another/topic"​, ​"roleArn"​:​ ​"arn:aws:iam::964391593426:role/iot-actions-role" ​} ​}] } 【其他AWS IoT範例請參考以下連結】 http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/aws-iot-rule-actions.html 【Viewing Your Rules】 $ aws iot list-topic-rules $ aws iot get-topic-rule --rule-name ​<value> 【Deleting a Rule】 $ aws iot delete-topic-rule --rule-name ​<value> 【AWS IoT SQL Reference】 關於其他SQL指令用法如select, from, where或是function()請參考以下連結 http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/aws-iot-sql-reference.html 8. Device Shadows for AWS IoT (MQTT) Device Shadows Device Shadow是用來取回/儲存當前狀態的JSON檔案,開發者可以經由 MQTT/HTTP 取得與設定裝置 參數,Shadow是使用保留的MQTT topics來讓Applications和裝置(Device)可以進行 GET/UPDATE/DELETE等功能。 【Device Shadow Document Example】 { ​"state"​ ​:​ ​{ ​"desired"​ ​:​ ​{ ​//​ Applications將欲更新的狀態寫到desired,而不是直接跟device連結
  • 13. ​"color"​ ​:​ ​"RED"​, ​"sequence"​ ​:​ ​[​ ​"RED"​,​ ​"GREEN"​,​ ​"BLUE"​ ​] ​}, ​"reported"​ ​:​ ​{ ​//​ 裝置(Device)將當前的狀態寫到reported,Applications便可從reported取得裝置 (Device)狀態,而不需直接與裝置(Device)連結 ​"color"​ ​:​ ​"GREEN" ​} ​}, ​"metadata"​ ​:​ ​{ ​//用來存放裝置metadata,並紀錄資料異動的時間 ​"desired"​ ​:​ ​{ ​"color"​ ​:​ ​{ ​"timestamp"​ ​:​ ​12345 ​}, ​"sequence"​ ​:​ ​{ ​"timestamp"​ ​:​ ​12345 ​} ​}, ​"reported"​ ​:​ ​{ ​"color"​ ​:​ ​{ ​"timestamp"​ ​:​ ​12345 ​} ​} ​}, ​"version"​ ​:​ ​10​, ​//表示document version,每次更新shadow就+1 ​"clientToken"​ ​:​ ​"UniqueClientToken"​, ​//一串unique string,用來確認MQTT req/res是否有相關 ​"timestamp"​:​ ​123456789 ​//表示訊息在什麼時間點透過AWS IoT傳送 } 【Device Shadow MQTT Pub/Sub Messages】 保留的MQTT topics命名規則為​$aws/things/​thingName​/shadow + Messages(如下) Messages ● /update ● /update/accepted ● /update/rejected ● /update/delta ● /get ● /get/accepted ● /get/rejected ● /delete ● /delete/accepted ● /delete/rejected 【Request State Documents】 { ​"state"​:​ ​{ ​"desired"​:​ ​{ ​"attribute1"​:​ integer2​, ​"attribute2"​:​ ​"string2"​, ​... ​"attributeN"​:​ boolean2 ​}, ​"reported"​:​ ​{ ​"attribute1"​:​ integer1​, ​"attribute2"​:​ ​"string1"​, ​... ​"attributeN"​:​ boolean1 ​} ​}
  • 14. ​"clientToken"​:​ ​"token"​, ​"version"​:​ version } 【Response State Documents】 { ​"state"​:​ ​{ ​"desired"​:​ ​{ ​"attribute1"​:​ integer2​, ​"attribute2"​:​ ​"string2"​, ​... ​"attributeN"​:​ boolean2 ​}, ​"reported"​:​ ​{ ​"attribute1"​:​ integer1​, ​"attribute2"​:​ ​"string1"​, ​... ​"attributeN"​:​ boolean1 ​}, ​"delta"​:​ ​{ ​"attribute3"​:​ integerX​, ​"attribute5"​:​ ​"stringY" ​} ​}, ​"metadata"​:​ ​{ ​"desired"​:​ ​{ ​"attribute1"​:​ ​{ ​"timestamp"​:​ timestamp ​}, ​"attribute2"​:​ ​{ ​"timestamp"​:​ timestamp ​}, ​... ​"attributeN"​:​ ​{ ​"timestamp"​:​ timestamp ​} ​}, ​"reported"​:​ ​{ ​"attribute1"​:​ ​{ ​"timestamp"​:​ timestamp ​}, ​"attribute2"​:​ ​{ ​"timestamp"​:​ timestamp ​}, ​... ​"attributeN"​:​ ​{ ​"timestamp"​:​ timestamp ​} ​} ​}, ​"timestamp"​:​ timestamp​, ​"clientToken"​:​ ​"token"​, ​"version"​:​ version } 【Error Response Documents】 { ​"code"​:​ error​-​code​, ​"message"​:​ ​"error-message"​, ​"timestamp"​:​ timestamp​, ​"clientToken"​:​ ​"token" }
  • 15. 【MQTT Pub/Sub Messages】 /update  publish到該topic,用來更新 thing shadow  $aws/things/​thingName​/shadow/update  AWS IoT responds by publishing to either​ ​/update/accepted​ or ​/update/rejected Example Policy The following is an example policy: { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Publish"​], ​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/update"​] ​}] } /update/accepted 當AWS IoT接收到 thing shadow有更新時會response state document到該topic $aws/things/​thingName​/shadow/update/accepted Example Policy  The following is an example policy:  { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​], ​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/update/accepted"​] ​}] } /update/rejected 當 AWS IoT拒絕 thing shadow 更新時會 response error document 到該 topic $aws/things/​thingName​/shadow/update/rejected Example Policy  The following is an example policy:  { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​], ​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/update/rejected"​] ​}] }
  • 16. /update/delta 當AWS IoT接收到 thing shadow有更新時,​且 desired state 與 reported state 不一致​時會response state document到該topic $aws/things/​thingName​/shadow/update/delta Example Policy  The following is an example policy:  { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​], ​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/update/delta"​] ​}] } /get  publish到該topic,用來取得 thing shadow  $aws/things/​thingName​/shadow/get  AWS IoT responds by publishing to either ​/get/accepted​ ​or​ ​/get/rejected​. Example Policy The following is an example policy: { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Publish"​], ​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/get"​] ​}] } /get/accepted  當 AWS IoT接收到 thing shadow /get 時會 response state document 到該topic  $aws/things/​thingName​/shadow/get/accepted  Example Policy The following is an example policy: { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​], ​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/get/accepted"​]
  • 17. ​}] } /get/rejected  當 AWS IoT 無法 return thing shadow 時會 response error document 到該 topic  $aws/things/​thingName​/shadow/get/rejected  Example Policy The following is an example policy: { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​], ​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/get/rejected"​] ​}] } /delete publish到該topic,用來刪除 thing shadow,訊息內容( Request state document )可忽略 $aws/things/​thingName​/shadow/delete AWS IoT responds by publishing to either ​/delete/accepted​ or ​/delete/rejected​. Example Policy  The following is an example policy:  { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​], ​"Resource"​:​ ​[​"arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/delete"​] ​}] }   /delete/accepted  當 AWS IoT 接收到 thing shadow /delete 時會 response state document 到該topic  $aws/things/​thingName​/shadow/delete/accepted  Example Policy The following is an example policy: { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​],
  • 18. ​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/delete/accepted"​] ​}] } /delete/rejected  當 AWS IoT 無法刪除 thing shadow 時會 response error document 到該 topic  $ aws/things/​thingName​/shadow/delete/rejected  Example Policy The following is an example policy: { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​"iot:Subscribe"​], ​"Resource"​:​ ​[​"arn:aws:iot:​region​:​account​:topic/$aws/things/​thingName​/shadow/delete/rejected"​] ​}] } 【Demo】 模擬裝置 Update "reported” $ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state": {"reported" : {"power" : "on"}}}'​ ​outfile.json 模擬手機App Update "desired” $ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state": {"desired" : {"power" : "off"}}}'​ ​outfile2.json 模擬取得 Shadow Thing "delta” $ aws iot-data get-thing-shadow --thing-name ​<value>​ ​outfile3.json 可取得”​delta​”區塊的資料,表示”reported”和”desired”資料不同步 { "state"​:​ ​{ ​"desired"​:​ ​{ ​"power"​:​ ​"on" ​}, ​"reported"​:​ ​{ ​"power"​:​ ​"off" ​}, ​"delta": { "power": "on" } } } 模擬同步 Shadow Thing "delta” $ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state": {"reported" : {"power" : "on"}}}'​ ​outfile4.json 模擬再次取得 Shadow Thing "delta” $ aws iot-data get-thing-shadow --thing-name ​<value>​ ​outfile5.json
  • 19. 可發現”reported”和”desired”區塊的資料已同步完成 { "state"​:​ ​{ ​"desired"​:​ ​{ ​"power"​:​ ​"on" ​}, ​"reported"​:​ ​{ ​"power"​:​ ​"​on​" ​}​, "delta": { "power": "on" } } } 模擬 Version conflict $ aws iot-data update-thing-shadow --thing-name ​<value>​ --payload ​'{"state": {"reported" : {"power" : "on"}}, “version” : 1}'​ ​outfile6.json 會出現錯誤訊息 ​A client error (ConflictException) occurred when calling the UpdateThingShadow operation: ​Version conflict 【MQTT Pub/Sub Messages】 HTTP Error Code Error Messages 400 (Bad Request) ● Invalid JSON ● Missing required node: state ● State node must be an object ● Desired node must be an object ● Reported node must be an object ● Invalid version ● Invalid clientToken ● JSON contains too many levels of nesting; maximum is 6 ● State contains an invalid node 401 (Unauthorized) ● Unauthorized 403 (Forbidden) ● Forbidden 404 (Not Found) ● Thing not found 409 (Conflict) ● Version conflict 413 (Payload Too Large) ● The payload exceeds the maximum size allowed 415 (Unsupported Media Type) ● Unsupported documented encoding; supported encoding is UTF-8
  • 20. 500 (Internal Server Error) ● Internal service failure 9. AWS IoT SDK ( Node.js ) 安裝 AWS IoT SDK - 以 Raspberry Pi 為例 ( Linkit 7688 也適用) 官方詳細安裝步驟 Install the AWS IoT Device SDK for Node.js & Example https://github.com/aws/aws-iot-device-sdk-js $ npm install aws-iot-device-sdk Download root-CA Download ​root-CA $ curl -o ​root-CA.crt​ https://www.symantec.com/cont ent/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primar y-Certificatio n-Authority-G5.pem 【Provision a Certificate】 $ aws iot create-keys-and-certificate --set-as-active --certificate-pem-outfile ​cert.pem​ --public-key-outfile publicKey.pem​ --private-key-outfile ​privateKey.pem
  • 21. Get endpoint $ aws iot describe-endpoint Examples 【Device class】 awsIot.device(option),option也可以是mqtt.js支援的參數 https://github.com/mqttjs/MQTT.js/blob/master/README.md#client var​ awsIot ​=​ ​require​(​'aws-iot-device-sdk'​); var​ device ​=​ awsIot.​device​({ keyPath​:​ ​'~/awsCerts/private.pem.key'​, certPath​:​ ​'~/awsCerts/certificate.pem.crt'​, caPath​:​ ​'~/awsCerts/root-CA.crt'​, clientId​:​ ​'myAwsClientId'​, region​:​ ​'us-east-1' }); // // Device is an instance returned by mqtt.Client(), see mqtt.js for full // documentation. // device .​on​(​'connect'​, ​function​() { ​console​.​log​(​'connect'​); device.​subscribe​(​'topic_1'​); device.​publish​(​'topic_2'​, ​JSON​.​stringify​({ test_data​:​ ​1​})); }); device .​on​(​'message'​, ​function​(topic, payload) { ​console​.​log​(​'message'​, topic, payload.​toString​()); }); 10. AWS IoT Troubleshooting AWS IoT Troubleshooting
  • 22. 1. The thing shadow supports 8 KB of data only. 2. 建立 AWS CloudWatch 來查看 AWS IoT Logging https://ap-northeast-1.console.aws.amazon.com/cloudwatch/home?region=ap-northeast-1 #logs: 【Create an IAM Role for AWS IoT】 $ aws iam create-role --role-name ​<value> --assume-role-policy-document ​<file://path-to-your-policy-document> Assume Logging Role policy document.json example { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[ ​{ ​"Sid"​:​ ​""​, ​"Effect"​:​ ​"Allow"​, ​"Principal"​:​ ​{ ​"Service"​:​ ​"iot.amazonaws.com" ​}, ​"Action"​:​ ​"sts:AssumeRole" ​} ​] } 【Grant Permissions to the Role】 【Create IAM policy】 該步驟可省略,IAM已經有內建的 CloudWatch 相關的 Policy 可直接使用,透過指令來查 詢有哪些可用的Policy $ aws iam list-policies | grep CloudWatch $ aws iam create-policy --policy-name ​<value>​ --policy-document <file://IAM-policy-document-file-path> *把Arn記下來! 或是輸入 aws iam list-roles來查詢 IAM policy document.json example Action部份依照需求調整 { ​"Version"​:​ ​"2012-10-17"​, ​"Statement"​:​ ​[{ ​"Effect"​:​ ​"Allow"​, ​"Action"​:​ ​[​ ​"dynamodb:*"​,​ ​"lambda:InvokeFunction"​,​ ​"iot:Publish"​], ​"Resource"​:​ ​[​"*"​] ​}] } 【Attach IAM policy】 $ ​aws iam attach-role-policy --role-name ​<value>​ --policy-arn arn:aws:iam::964391593426:role/iot-actions-role *可輸入 aws iam list-roles來查詢各個Role的Arn 【Register the Logging Role with AWS IoT】 $ aws iot set-logging-options --logging-options-payload roleArn="arn:aws:iam::​<your-aws-account-num>​:​role/IoTLoggingRole​",log Level="​INFO​" 更多關於 AWS CloudWatch 的設定請參閱以下連結:
  • 23. http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/cloud-watc h-logs.html 11. AWS IoT Limits AWS IoT Limits Topic length limit 256 bytes encoded in UTF-8. Restricted topic prefix Topics開頭’​$​’是保留字,除了 Thing Shadows 外都不可使用 Maximum number of slashes in topic and topic filter 最多8個 slashes (/) Client ID size limit 128 bytes encoded in UTF-8. Restricted client ID prefix ’​$​’ 是 client IDs 保留字 Message size limit payload 最多 128 KB,若超過大小會被 AWS IoT Service reject Throughput per connection AWS IoT limits the ingress and egress rate on each client connection to 512 KB/s. Data sent or received at a higher rate will be throttled to this throughput. Maximum subscriptions per subscribe call A single subscribe call is limited to request a maximum of eight subscriptions. Subscriptions per session The message broker limits each client session to subscribe to up to 50 subscriptions. A subscribe request that pushes the total number of subscriptions past 50 will result in the connection being disconnected. Connection inactivity (keep-alive) limits 預設30秒沒有任何動作則斷開連結,也可設 定更短的keep-alive,範圍5~1200秒,設定 <5秒則以5秒為預設;設定0秒則以預設值執 行 Maximum inbound unacknowledged messages The message broker allows 100 in-flight unacknowledged messages (limit is across all messages requiring ACK). When this limit is reached, no new messages will be accepted until an ACK is returned by the server. Maximum outbound unacknowledged messages The message broker only allows 100 in-flight unacknowledged messages (limit is across all messages requiring ACK). When
  • 24. this limit is reached, no new messages will be sent to the client until the client acknowledges the in-flight messages. Maximum retry interval for delivering QoS 1 messages If a connected client is unable to receive an ACK on a QoS 1 message for one hour, the message broker will drop the message. The client may be unable to receive the message if it has 100 in-flight messages, it is being throttled due to large payloads, or other errors. WebSocket connection duration WebSocket連線限制為5分鐘,超過則會斷 線,若要連線超過5分鐘,則在 client 端關閉 連線並重開即可
  • 25. AWS IoT Rule Engine 與 AWS Lambda結合 1. 在​AWS Lambda​建立測試用的Function,也可用CLI產出Rule,語法如下: 產出Rule $ aws iot create-topic-rule --rule-name my-rule-name --topic-rule-payload file://my-rule.json-path // my-rule.json { ​"sql"​:​ ​"expression"​, ​"ruleDisabled"​:​ ​false​, ​"actions"​:​ ​[{ ​"lambda"​:​ ​{ ​"functionArn"​:​ ​"arn:aws:lambda:us-west-2:123456789012:function:my-lambda-function" ​} ​}] } 2. 在AWS IoT建立Rule,觸發Rule後將payload轉送到Lambda Function 3. 使用MQTTfx發送會觸發Rule的payload { ​"key1"​:​"111", ​"key2"​:​"222", ​"key3"​:​"333" } 4. 在​AWS CloudWatch​查看Lambda Log,就可以看到觸發Rule後所轉送過來的資料
  • 26. Demo1: 展示直接連結Device node /root/project/aws/device.js MQTTfx: subscribe “test2” MQTTfx: publish “test1” Demo2: 用Demo1展示Rule engine Rule Engine設置republish to "rep/test” Demo3: 展示透過shadow thing來溝通而不是直接連結裝置 接收端(led燈): node /root/project/aws/shadowThing.js 發送端:node /root/project/aws2/thing-passthrough-example.js --test-mode=1 用MQTTfx來觀看實際註冊情形,先subscribe以下幾組: http://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/thing-shadow-data-flow.html $aws/things/myLightBulb/shadow/update/accepted  The Thing Shadows service sends messages to this topic when an update is  successfully made to a thing shadow.  $aws/things/myLightBulb/shadow/update/rejected  The Thing Shadows service sends messages to this topic when an update to a  thing shadow is rejected.  $aws/things/myLightBulb/shadow/update/delta  The Thing Shadows service sends messages to this topic when a difference is  detected between the reported and desired sections of a thing shadow.  $aws/things/myLightBulb/shadow/get/accepted  The Thing Shadows service sends messages to this topic when a request for a  thing shadow is made successfully.  $aws/things/myLightBulb/shadow/get/rejected  The Thing Shadows service sends messages to this topic when a request for a  thing shadow is rejected.