aws iot - 開発者ガイド · aws iot 開発者ガイド...

889
AWS IoT 開発者ガイド

Upload: lytuyen

Post on 26-Jul-2018

331 views

Category:

Documents


6 download

TRANSCRIPT

  • AWS IoT

  • AWS IoT

    AWS IoT: Copyright 2018 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

    Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any mannerthat is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks notowned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored byAmazon.

  • AWS IoT

    Table of ContentsAWS IoT .................................................................................................................................... 1

    AWS IoT ................................................................................................................... 1AWS IoT ................................................................................................................... 2AWS IoT ................................................................................................................ 2 ............................................................................................................................. 3AWS IoT ...................................................................................................................... 3

    AWS IoT ........................................................................................................................... 5AWS IoT .......................................................................................... 5Registry .................................................................................................... 6 .................................................................................. 8AWS IoT ..................................................................................................... 10AWS IoT ...................................................................... 12 ...................................................................................................... 14 .................................................................................................................. 17

    AWS IoT ................................................................................................ 17 .......................................................................................................... 18

    AWS IoT MQTT MQTT ......................................... 18 ...................................................................................................... 21

    SNS ................................................................................................... 21Amazon SNS ....................................................................... 23 .............................................................................................................. 24Amazon SNS ....................................................................................... 29 .................................................................................................................... 30

    AWS IoT .................................................................................................... 31AWS IoT ............................................................................ 31AWS IoT AWS CloudFormation ............................................................ 40 ............................................................................................................................ 45

    AWS IoT ....................................................................................................... 46DynamoDB ........................................................................................................... 46Lambda ............................................................................................................... 54

    Lambda .................................................................................................... 54Lambda ................................................................................................. 62Lambda ....................................................................................................... 64Lambda .............................................................................................. 67

    Amazon SNS .................................................................................................. 69AWS IoT SDK ........................................................................................................... 77

    Raspberry Pi .................................................................................................................. 77 .......................................................................................................................... 77AWS IoT ................................................................................. 77 ............................................................................ 79

    AWS IoT Embedded C SDK ............................................................................................ 86AWS IoT Embedded C SDK ...................................................... 86 ........................................................................................ 86 .................................................................................. 88

    AWS IoT Device SDK for JavaScript ........................................................................... 89AWS IoT Device SDK for JavaScript ........................................... 89AWS IoT Device SDK for JavaScript ....................................................... 90 ......................................................................... 90 .................................................................................. 91

    AWS IoT .......................................................................................................... 92 ................................................................................................ 92

    ....................................................................................................................... 92 .............................................................................................................. 93 ....................................................................................................................... 93

    iii

  • AWS IoT

    ....................................................................................................................... 94 ....................................................................................................................... 95 ..................................................................................... 95 .................................................................................. 95

    ............................................................................................................................ 95 .................................................................................................... 96 ........................................................................................... 96 .................................................................................................... 96 ........................................................................................ 97 .............................................................................................. 97 .................................................................................................... 98

    ......................................................................................................................... 98 ....................................................................................................... 99 ...................................................................................................... 100 ............................................................................................. 101 ................................................................................... 101 ................................................................................... 101 ................................................................................................ 102 ................................................................................................ 103 ...................................................................................................... 104 ................................................................................................ 104 .......................................................................... 104 .................................................................... 105 ..................................................... 105 ................................................................................... 105 ...................................................................................... 106MQTT ......................................................................................... 106

    ......................................................................................................................... 108AWS IoT ........................................................................................................................ 108

    X.509 .................................................................................................................. 109IAM ...................................................................................... 116Amazon Cognito ID ......................................................................................................... 116

    .......................................................................................................................... 117 ................................................................................................... 117 ................................................................................................... 118 ............................................................................. 119

    ...................................................................................................................................... 120AWS IoT .......................................................................................................... 122IAM IoT ............................................................................................................ 142

    AWS ......................................................................................... 149 ........................................................ 151

    ........................................................................................................ 153 ..................................................................................................... 154

    TLS ............................................................................................ 154 ...................................................................................................................... 156

    ............................................................................................................................. 156/ ............................................................................................ 156MQTT ............................................................................................................................ 156HTTP ............................................................................................................................ 157MQTT over WebSocket ................................................................................... 158

    ................................................................................................................................ 161 ......................................................................................................... 162

    ......................................................................................................... 165/ ........................................................................................................... 165/ ...................................................................... 166

    ........................................................................................................................................... 168AWS IoT .................................................................................... 168

    iv

  • AWS IoT

    ..................................................................................................... 170AWS IoT ............................................................................................................ 171 .......................................................................................................................... 174SQL ...................................................................................................................... 174

    SQL 2016-03-23 ....................................................... 175 .............................................................................................. 176 .................................................................................................................... 176

    ...................................................................................... 176 ...................................................................................................... 177

    .......................................................................................................................... 178AWS IoT ...................................................................................................... 178

    CloudWatch ....................................................................................... 179CloudWatch .................................................................................... 179DynamoDB .................................................................................................... 180DynamoDBv2 ................................................................................................. 182Amazon ES ................................................................................................... 182Firehose ........................................................................................................ 183Kinesis .......................................................................................................... 184Lambda ......................................................................................................... 185Republish ...................................................................................................... 186S3 ................................................................................................................ 186SNS .............................................................................................................. 187SQS ............................................................................................................. 188Salesforce ..................................................................................................... 189IoT Analytics .................................................................................................. 189

    AWS IoT SQL ..................................................................................................... 190 ........................................................................................................................ 191 ........................................................................................................................... 194 .............................................................................................................................. 200SELECT .................................................................................................................... 231FROM ....................................................................................................................... 233WHERE ..................................................................................................................... 234 ........................................................................................................................ 234Case ....................................................................................................... 235JSON ..................................................................................................................... 235 ............................................................................................................ 236

    Device Shadow ................................................................................................................. 238Device Shadow .................................................................................... 238

    ............................................................................................................ 244Device Shadow .................................................................................... 246

    ................................................................................................ 246 ................................................................................... 247 ...................................................................................................... 247 ............................................................................................................ 247 ............................................................................................................... 248 .............................................................................................................................. 248

    ....................................................................................................................... 249 ...................................................................................................... 249 ............................................................................................................... 249Shadow ........................................................................................... 250 .................................................................................................................. 253 ............................................................................................................... 254delta ...................................................................................................................... 254 ............................................................................................................ 256 ............................................................................................................ 256 ............................................................................................. 257

    RESTful API ........................................................................................................................... 258

    v

  • AWS IoT

    GetThingShadow ............................................................................................................. 258UpdateThingShadow ........................................................................................................ 259DeleteThingShadow ......................................................................................................... 259

    MQTT / .............................................................................. 260/update .......................................................................................................................... 261/update/accepted ............................................................................................................. 261/update/documents .......................................................................................................... 262/update/rejected .............................................................................................................. 262/update/delta ................................................................................................................... 263/get ............................................................................................................................... 264/get/accepted .................................................................................................................. 264/get/rejected .................................................................................................................... 264/delete ........................................................................................................................... 265/delete/accepted .............................................................................................................. 265/delete/rejected ............................................................................................................... 266

    ................................................................................................................. 266 ............................................................................................. 267 ............................................................................................. 267 ......................................................................................... 268

    .................................................................................................................... 269 ........................................................................................................................................... 270

    .................................................................................................................... 270 .................................................................................................................... 271

    .................................................................................................................. 271 ......................................................................................................... 273 ............................................................................................. 273 ............................................................................................................ 274 ................................................................................................ 274 ......................................................................................................... 275 ................................................................................................................. 276 ......................................................................................................... 276 ................................................................................................ 277 ............................................................................................................ 278 ...................................................................................................... 278 ............................................................................................................... 279

    .................................................................................................................... 281 ....................................................................... 283

    AWS IoT API ..................................................................................................... 292 API ...................................................................................................... 292Jobs Device MQTT HTTPS API .............................................................................. 334

    .......................................................................................................................... 356 ................................................................................................................ 357

    ................................................................................................. 357Parameters .................................................................................................... 357Resources ..................................................................................................... 358 ............................................................................................................ 361

    ........................................................................................... 363 ..................................................................................... 364 .............................................................................................................. 367

    ................................................................................................... 368 ........................................................................................................... 368

    ................................................................................................ 368 ......................................................................................................... 369 ......................................................................................................... 369 ...................................................................................................... 370 ......................................................................................................... 371 ..................................................................................................................... 372

    vi

  • AWS IoT

    .............................................................................................................................. 373AWS IoT .......................................................................................................................... 374

    .......................................................................................................................... 374 ....................................................................................................................... 381

    AWS IoT SDK ................................................................................................................................ 383AWS Mobile SDK for Android ................................................................................................... 383Arduino Yn SDK .................................................................................................................... 383AWS IoT Device SDK for Embedded C ...................................................................................... 383AWS IoT C++ Device SDK ....................................................................................................... 384AWS Mobile SDK for iOS ......................................................................................................... 384AWS IoT Device SDK for Java .................................................................................................. 384AWS IoT Device SDK for JavaScript .......................................................................................... 384AWS IoT Device SDK for Python .............................................................................................. 385

    .................................................................................................................................. 386 ................................................................................................................. 386

    .................................................................................................................. 387 ..................................................................................................................... 387

    Amazon CloudWatch ...................................................................................... 387 ............................................................................................. 388AWS IoT ........................................................................................... 393CloudWatch ............................................................................................. 394

    AWS CloudTrail AWS IoT API ...................................................... 396CloudTrail AWS IoT .......................................................................................... 396AWS IoT ............................................................................... 397

    ................................................................................................................... 399 .............................................................................................................. 399

    .............................................................................................................................. 399 .............................................................................................................................. 399

    AWS IoT CloudWatch Logs ............................................................................ 399 ................................................................................................ 400 ..................................................................................................................... 400AWS IoT ................................................................................................. 401CloudWatch ....................................................................................... 403 ..................................................................................................................... 415 ................................................................................................... 416

    Shadow ...................................................................................................... 417Salesforce ........................................................................................... 418

    .................................................................................................................. 418 Success Failure .......................................................................................... 418

    AWS IoT ..................................................................................................................... 419AWS IoT ..................................................................................................................... 419

    IOT ................................................................................................................................. 421AcceptCertificateTransfer ......................................................................................................... 424AddThingToThingGroup .......................................................................................................... 426AssociateTargetsWithJob ........................................................................................................ 428AttachPolicy .......................................................................................................................... 432AttachPrincipalPolicy ............................................................................................................... 434AttachThingPrincipal ............................................................................................................... 436CancelCertificateTransfer ........................................................................................................ 438CancelJob ............................................................................................................................. 441CancelJobExecution ............................................................................................................... 444ClearDefaultAuthorizer ............................................................................................................ 449CreateAuthorizer .................................................................................................................... 450CreateCertificateFromCsr ........................................................................................................ 454CreateJob ............................................................................................................................. 457CreateKeysAndCertificate ........................................................................................................ 463CreateOTAUpdate .................................................................................................................. 466

    vii

  • AWS IoT

    CreatePolicy .......................................................................................................................... 473CreatePolicyVersion ............................................................................................................... 476CreateRoleAlias ..................................................................................................................... 480CreateStream ........................................................................................................................ 484CreateThing .......................................................................................................................... 488CreateThingGroup .................................................................................................................. 492CreateThingType ................................................................................................................... 496CreateTopicRule .................................................................................................................... 499DeleteAuthorizer .................................................................................................................... 516DeleteCACertificate ................................................................................................................ 518DeleteCertificate ..................................................................................................................... 520DeleteJob ............................................................................................................................. 523DeleteJobExecution ................................................................................................................ 526DeleteOTAUpdate .................................................................................................................. 530DeletePolicy .......................................................................................................................... 532DeletePolicyVersion ................................................................................................................ 534DeleteRegistrationCode ........................................................................................................... 536DeleteRoleAlias ..................................................................................................................... 537DeleteStream ........................................................................................................................ 539DeleteThing ........................................................................................................................... 541DeleteThingGroup .................................................................................................................. 544DeleteThingShadow ................................................................................................................ 546DeleteThingType .................................................................................................................... 548DeleteTopicRule ..................................................................................................................... 550DeleteV2LoggingLevel ............................................................................................................ 552DeprecateThingType ............................................................................................................... 554DescribeAuthorizer ................................................................................................................. 556DescribeCACertificate ............................................................................................................. 559DescribeCertificates ................................................................................................................ 563DescribeDefaultAuthorizer ....................................................................................................... 567DescribeEndpoint ................................................................................................................... 570DescribeEventConfigurations .................................................................................................... 572DescribeIndex ........................................................................................................................ 574DescribeJob .......................................................................................................................... 577DescribeJobExecution ............................................................................................................. 583DescribeJobExecution ............................................................................................................. 587DescribeRoleAlias .................................................................................................................. 591DescribeStream ..................................................................................................................... 594DescribeThing ....................................................................................................................... 598DescribeThingGroup ............................................................................................................... 602DescribeThingRegistrationTask ................................................................................................ 606DescribeThingType ................................................................................................................. 610DetachPolicy ......................................................................................................................... 614DetachPrincipalPolicy .............................................................................................................. 616DetachThingPrincipal .............................................................................................................. 618DisableTopicRule ................................................................................................................... 620EnableTopicRule .................................................................................................................... 622GetEffectivePolicies ................................................................................................................ 624GetIndexingConfiguration ........................................................................................................ 627GetJobDocument ................................................................................................................... 629GetLoggingOptions ................................................................................................................. 632GetOTAUpdate ...................................................................................................................... 633GetPendingJobExecutions ....................................................................................................... 640GetPolicy .............................................................................................................................. 644GetPolicyVersion .................................................................................................................... 647GetRegistrationCode ............................................................................................................... 650GetThingShadow ................................................................................................................... 652

    viii

  • AWS IoT

    GetTopicRule ........................................................................................................................ 655GetV2LoggingOptions ............................................................................................................. 672ListAttachedPolicies ................................................................................................................ 674ListAuthorizers ....................................................................................................................... 677ListCACertificates ................................................................................................................... 680ListCertificates ....................................................................................................................... 684ListCertificatesByCA ............................................................................................................... 687ListIndices ............................................................................................................................. 691ListJobExecutionsForJob ......................................................................................................... 693ListJobExecutionsForThing ...................................................................................................... 697ListJobs ................................................................................................................................ 701ListOTAUpdates ..................................................................................................................... 706ListOutgoingCertificates ........................................................................................................... 709ListPolicies ............................................................................................................................ 712ListPolicyPrincipals ................................................................................................................. 715ListPolicyVersions .................................................................................................................. 719ListPrincipalPolicies ................................................................................................................ 721ListPrincipalThings ................................................................................................................. 725ListRoleAliases ...................................................................................................................... 728ListStreams ........................................................................................................................... 730ListTargetsForPolicy ............................................................................................................... 734ListThingGroups ..................................................................................................................... 737ListThingGroupsForThing ........................................................................................................ 740ListThingPrincipals ................................................................................................................. 743ListThingRegistrationTaskReports ............................................................................................. 745ListThingRegistrationTasks ...................................................................................................... 748ListThingTypes ...................................................................................................................... 751ListThings ............................................................................................................................. 755ListThingsInThingGroup ........................................................................................................... 758ListTopicRules ....................................................................................................................... 761ListV2LoggingLevels ............................................................................................................... 764 ..................................................................................................................................... 767RegisterCACertificate .............................................................................................................. 769RegisterCertificate .................................................................................................................. 773RegisterThing ........................................................................................................................ 777RejectCertificateTransfer ......................................................................................................... 780RemoveThingFromThingGroup ................................................................................................. 783ReplaceTopicRule .................................................................................................................. 785SearchIndex .......................................................................................................................... 802SetDefaultAuthorizer ............................................................................................................... 806SetDefaultPolicyVersion .......................................................................................................... 809SetLoggingOptions ................................................................................................................. 811SetV2LoggingLevel ................................................................................................................. 813SetV2LoggingOptions ............................................................................................................. 815StartNextPendingJobExecution ................................................................................................. 817StartThingRegistrationTask ...................................................................................................... 821StopThingRegistrationTask ...................................................................................................... 824TestAuthorization ................................................................................................................... 826TestInvokeAuthorizer .............................................................................................................. 833TransferCertificate .................................................................................................................. 837UpdateAuthorizer ................................................................................................................... 840UpdateCACertificate ............................................................................................................... 844UpdateCertificate .................................................................................................................... 847UpdateEventConfigurations ...................................................................................................... 849UpdateIndexingConfiguration .................................................................................................... 851UpdateJobExecution ............................................................................................................... 853UpdateRoleAlias .................................................................................................................... 859

    ix

  • AWS IoT

    UpdateStream ....................................................................................................................... 862UpdateThing .......................................................................................................................... 866UpdateThingGroup ................................................................................................................. 870UpdateThingGroupsForThing ................................................................................................... 874UpdateThingShadow ............................................................................................................... 876

    x

  • AWS IoT AWS IoT

    AWS IoT AWS IoT () AWS

    AWS IoT AWS IoT

    AWS IoT

    AWS IoT MQTT WebSocket HTTP REST

    AWS SQL (Amazon S3AmazonDynamoDBAWS Lambda )

    AWS AWS AWS

    [Registry]

    AWS 3 MQTT ID

    JSON

    1

  • AWS IoT AWS IoT

    Device Shadow

    AWS

    (1 ) AWS IoT AWS IoT

    ()

    Lambda AWS IoT

    (JSON Web OAuth ) MQTT

    AWS IoT 1

    AWS IoT AWS IoT

    AWS IoT AWS IoT AWS IoT (p. 3) AWS IoT AWS IoT (p. 5)

    AWS IoT AWS IoT

    AWS Command Line Interface (AWS CLI) - WindowsmacOSLinux AWS IoT AWS Command Line Interface AWS IoTAWS CLI Command Referenceiot

    2

    http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#limits_iothttp://docs.aws.amazon.com/cli/latest/userguide/http://docs.aws.amazon.com/cli/latest/reference/iot/index.html

  • AWS IoT

    AWS IoT API - HTTP HTTPS IoT API AWS IoT API AWS IoT API

    AWS SDK - API IoT SDK HTTP/HTTPS API AWS SDK

    [AWS IoT Device SDKs]AWS IoT AWS IoT SDK

    AWS IoT AWS

    Amazon Simple Storage Service - AWS Amazon S3

    Amazon DynamoDB - NoSQL AmazonDynamoDB

    Amazon Kinesis - Amazon Kinesis

    AWS Lambda - Amazon EC2 AWS Lambda

    Amazon Simple Notification Service - AmazonSNS

    Amazon Simple Queue Service - Amazon SQS

    AWS IoT AWS IoT AWS IoT

    MQTT JSON MQTT MQTT AWS IoT MQTT MQTT

    AWS IoT X.509 AWS IoT AWS IoT AWS IoT AWSIoT

    AWS IoT AWS IoT

    1 DynamoDB Lambda

    3

    http://docs.aws.amazon.com/iot/latest/apireference/API_Operations.htmlhttp://docs.aws.amazon.com/iot/latest/apireference/API_Operations.htmlhttp://aws.amazon.com/tools/#sdkhttp://docs.aws.amazon.com/iot/latest/developerguide/iot-sdks.htmlhttps://aws.amazon.com/s3/https://aws.amazon.com/dynamodb/https://aws.amazon.com/dynamodb/https://aws.amazon.com/kinesis/https://aws.amazon.com/lambda/https://aws.amazon.com/sns/https://aws.amazon.com/sns/https://aws.amazon.com/sqs/

  • AWS IoT AWS IoT

    AWS AWS IoT IAM

    2 Shadow reported desired JSON Shadow

    4

  • AWS IoT AWS IoT

    AWS IoT AWS IoT MQTT

    Wi-Fi AWS IoT () AWS IoT MQTT

    AWS IoT AWS IoT (p. 1)

    AWS IoT AWS

    AWS :

    1. AWS [Create an AWS Account] 2.

    PIN 3. AWS AWS IoT 4. [Welcome] [Get started]

    5

    https://www.amazon.com/All-New-AWS-IoT-Button-Generation/dp/B01KW6YCIM/ref=dp_ob_title_defhttps://aws.amazon.com/https://console.aws.amazon.com/iot/home

  • AWS IoT Registry

    AWS IoT [Welcome to the AWS IoT Console]

    Registry AWS IoT Registry AWS IoT

    AWS [IoT] iOS Android AWS IoT AWS Lambda Lambda E AWS Apple App Store Google Play

    Registry

    1. [AWS IoT ] [] []

    6

    https://itunes.apple.com/us/app/aws-iot-button/id1178216626?mt=8https://play.google.com/store/apps/details?id=com.amazonaws.iotbutton

  • AWS IoT Registry

    2. [You don't have any things yet] [Register a thing]

    3. [AWS IoT ] []

    7

  • AWS IoT

    4. [] [] (MyIoTButton) []

    AWS IoT X.509 AWS IoT X.509 AWS IoT X.509

    1. [Create certificate]

    8

  • AWS IoT

    2. [Certificate created!] AWS IoT CA [Download] ()[Activate]

    [! .

    2a540e2346-certificate.pem.crt 2a540e2346-private.pem.key 2a540e2346-public.pem.key

    Note

    CA CA

    3. [AWS IoT]

    9

  • AWS IoT AWS IoT

    AWS IoT AWS IoT X.509 MQTT AWS IoT AWS IoT AWS IoT AWS IoT AWS IoT

    AWS IoT

    1. [Secure] [Policies] [You don't have a policyyet] [Create a policy]

    2. [Create a policy] [Name] (MyIoTButtonPolicy)[Action] iot:Connect[Resource ARN] *[Allow] AWS IoT

    10

  • AWS IoT AWS IoT

    Note

    ARN () ARN arn:aws:iot:your-region:your-aws-account:client/

    [Add Statement] [Action] iot:Publish[Resource ARN] ARN

    Note

    ARN arn:aws:iot:your-region:your-aws-account:topic/iotbutton/your-button-serial-number(:arn:aws:iot:us-east-1:123456789012:topic/iotbutton/G030JF055364XVRBAWS IoT ARN topic/ (:arn:aws:iot:us-east-1:123456789012:topic/my/topic/here

    [Allow]

    3. [Create]

    11

  • AWS IoT AWS IoT

    Managing AWS IoT Policies

    AWS IoT

    AWS IoT

    1. [Secure] [Certificates]

    12

    http://docs.aws.amazon.com/iot/latest/developerguide/authorization.html

  • AWS IoT AWS IoT

    2. [...] [Attachpolicy]

    3. [Attach policies to certificate(s)] [Attach]

    13

  • AWS IoT

    AWS IoT CA AWS IoT AWS IoT . (p. 128)

    Registry

    1. [...] [Attach thing]

    14

  • AWS IoT

    2. [Attach things to certificate(s)] [Attach]

    3.

    15

  • AWS IoT

    4. [Details] [Things]

    5. [Details] [Policies]

    16

  • AWS IoT

    Wi-Fi AWS IoT Wi-Fi AWS IoT CA

    Note

    AWS IoT 15 Wi-Fi

    AWS IoT AWS IoT AWS IoT Apple App Store Google Play

    1. AWS IoT (

    15 )2. Wi-Fi Wi-Fi

    Button ConfigureMe - XXX (XXX 3 ) Wi-Fi

    Note

    Wi-Fi Wi-Fi Wi-Fi

    3. Wi-Fi WPA2-PSK (DSN) 8 DSN

    AWS IoT AWS IoT AWS IoT

    1. http://192.168.0.1/index.html 2.

    Wi-Fi SSID

    17

    https://itunes.apple.com/us/app/aws-iot-button/id1178216626https://play.google.com/store/apps/details?id=com.amazonaws.iotbuttonhttp://192.168.0.1/index.html

  • AWS IoT

    2a540e2346-certificate.pem.crt 2a540e2346-private.pem.key

    AWS IoT ([Manage] [Things] [Interact] [HTTPS] )

    ABCDEFG1234567.iot.us-east-2.amazonaws.com

    ABCDEFG1234567 us-east-2 [Button ConfigureMe] AWS IoT

    [Terms and Conditions]

    [Configure] Wi-Fi

    CA

    AWS IoT MQTT MQTT

    AWS IoT MQTT MQTT

    MQTT AWS IoT MQTT

    MQTT :

    1. AWS IoT [Test]

    18

    https://console.aws.amazon.com/iot/home?region=us-east-1#/dashboard/helphttps://console.aws.amazon.com/iot/home

  • AWS IoT AWS IoT MQTT MQTT

    2. AWS IoT iotbutton/+ (+ )[Subscribe to topic][Subscription topic] iotbutton/+[Subscribe to topic]

    [Subscribe to topic] [Subscriptions] iotbutton/+

    19

  • AWS IoT AWS IoT MQTT MQTT

    3. AWS IoT AWS IoT MQTT

    Note

    AWS IoT Button FAQs LED 4. AWS IoT

    MQTT [Publish] [Specifiy a topic and a message to publish]iotbutton/ABCDEFG12345 JSON

    { "serialNumber": "ABCDEFG12345", "clickType": "SINGLE", "batteryVoltage": "2000 mV"}

    20

    https://aws.amazon.com/iotbutton/faq

  • AWS IoT

    [Publish to topic] AWS IoT MQTT ( [Subscription] [iotbutton/+] )

    AWS IoT MQTT MQTT ( Amazon S3 Lambda Amazon SNS ) Amazon SNS

    Amazon SNS Amazon SNS Amazon SNS

    AWS IoT MQTT

    [Filter View] AWS IoT [AWS IoT Button] AWS IoT MQTT [MQTT Client]

    SNS Amazon SNS Amazon SNS

    Note

    Amazon SNS AWS

    1. Amazon SNS 2. [Topics]

    21

    https://console.aws.amazon.com/sns/v2/home

  • AWS IoT SNS

    3. [Create new topic]

    4. [Create topic]

    22

  • AWS IoT Amazon SNS

    5. ARN

    Amazon SNS SMS Amazon SNS

    1. Amazon SNS [Actions] [Subscribe to topic]

    2. [Create subscription] [Protocol] [SMS]

    [Endpoint] SMS [Create subscription]

    23

  • AWS IoT

    Note

    AWS IoT IAM IAM AWS IAM 1 1 1 AWS IoT

    Amazon SNS SMS

    1. AWS IoT [Act]

    2. [Act] [Create a rule]

    24

  • AWS IoT

    3. [Create a rule] [Name] [Description]

    4. [Message source] [Using SQL version] [Attribute] * MQTT

    25

  • AWS IoT

    5. MQTT [Topic filter] iotbutton/your-button-DSNAWS IoT my/topic

    Note

    DSN

    [Condition]

    6. [Set one or more actions] [Add action]

    26

  • AWS IoT

    7. [Select an action] [Send a message as an SNS push notification] [Configureaction]

    8. [Configure action] [SNS target] Amazon SNS

    27

  • AWS IoT

    9. Amazon SNS AWS IoT [Create a new role] [IAM role name] [Create a new role] [IAM rolename]

    10. [Update role] [Add action]

    28

  • AWS IoT Amazon SNS

    11. [Create a Rule] [Create rule]

    AWS IoT

    Amazon SNS AWS IoT AWS IoT MQTT

    AWS IoT SMS () ( 2 ) 2

    29

    http://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html

  • AWS IoT

    AWS IoT MQTT AWS IoT MQTT :

    1. AWS IoT [Test] 2. MQTT [Publish] [Specifiy a topic and a message to

    publish...] my/topic JSON

    { "message": "Hello, from AWS IoT console"}

    Note

    [Specifiy a topic and a message to publish...] my/topiciotbutton/your-button-DSN

    3. [Publish to topic] Amazon SNS

    Amazon SNS

    AWS IoT AWS IoT Rule Tutorials (p. 46)AWS IoTRules (p. 168)

    30

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

  • AWS IoT AWS IoT

    AWS IoT 2 AWS IoT AWS Lambda AWS IoT AWS IoT AWS Lambda AWS IoT

    AWS IoT X.509 Wi-Fi AWS IoT AWS IoT AWS IoT AWS IoT

    AWS IoT Lambda AWS IoT Lambda Amazon SNS E IAM

    Lambda E Lambda

    2 AWS IoT MQTT AWS IoT AWS CloudFormation

    AWS IoT AWS IoT (p. 1)

    AWS IoT (p. 31) AWS IoT AWS CloudFormation (p. 40) (p. 45)

    AWS IoT AWS IoT Lambda AWSLambda AWS

    AWS

    1. AWS [Create an AWS Account]

    31

    https://www.amazon.com/All-New-AWS-IoT-Button-Generation/dp/B01KW6YCIM/ref=dp_ob_title_defhttps://aws.amazon.com/

  • AWS IoT AWS IoT

    2. PIN

    AWS IoT

    1. AWS AWS Lambda 2. AWS Lambda [Get Started Now]

    AWS Lambda [Create a Lambda function]

    3. [Select blueprint] [Runtime] [Node.js 4.3] [filter] button[iot-button-email] [Next]

    32

    https://console.aws.amazon.com/lambda/home

  • AWS IoT AWS IoT

    4. [Configure triggers] [IoT Type] [IoT Button]

    (DSN)

    [Generate certificate and keys]

    Note

    http://192.168.0.1/index.html

    33

    http://192.168.0.1/index.html

  • AWS IoT AWS IoT

    34

  • AWS IoT AWS IoT

    AWS IoT 3 AWS IoT [Wi-Fi Configuration]Wi-Fi IDSSID[AWSIoT Configuration] AWS IoT AWS IoT [Configure]

    35

  • AWS IoT AWS IoT

    5. [Configure] AWS Lambda [Enable trigger] [Next]

    [Configure function] Lambda

    36

  • AWS IoT AWS IoT

    Lambda E E

    37

  • AWS IoT AWS IoT

    [Lambda function handler and role] [Role] [Create newrole from template(s)]

    [Next]

    Lambda [Create function]

    38

  • AWS IoT AWS IoT

    Lambda

    39

  • AWS IoT AWS IoT AWS CloudFormation

    6. Lambda [Test] 1 AWSNotification - Subscription Confirmation E E Lambda SNS AWS IoT AmazonSNS Lambda E Amazon SNS Amazon SNS AmazonSNS E

    AWS IoT Lambda Lambda Lambda SNS Lambda Amazon SNS Amazon SNS Lambda E

    AWS IoT AWS CloudFormation

    AWS IoT Amazon SNS E AWSCloudFormation AWS IoT

    AWS AWS IoT

    1. AWS IoT AWS IoT

    40

  • AWS IoT AWS IoT AWS CloudFormation

    a. AWS IoT b. [Welcome] [Get started] c. AWS AWS IoT AWS (:

    ()) AWS AWS ( AWS IoT Amazon SNS )

    d. [Dashboard] [Security] [Certificates]

    e. [Certificates] [Create] f. [One-click certificate creation] - [Create certificate] g. [Certificate created] AWS IoT CA

    [Download] [Activate] h. [Done] i. [Certificates] j. [Details] ARN (:arn:aws:iot:region-ID:account-ID:cert/

    random-ID) 2. https://console.aws.amazon.com/cloudformation/ AWS CloudFormation

    AWS IoT Amazon SNS IAM

    a. AWSIoTButtonQuickStart.template AWS CloudFormation

    Note

    DSN AllowedPattern DSN

    { "AWSTemplateFormatVersion": "2010-09-09", "Description": "Creates required AWS resources to allow an AWS IoT button to send information through an Amazon Simple Notification Service (Amazon SNS) topic to an email address.", "Parameters": { "IoTButtonDSN": { "Type": "String", "AllowedPattern": "G030[A-Z][A-Z][0=9][0-9][0-9][0-5][0-9][1-7][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X]", "Description": "The device serial number (DSN) of the AWS IoT Button. This can be found on the back of the button. The DSN must match the pattern of 'G030[A-Z][A-Z][0=9][0-9][0-9][0-5][0-9][1-7][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X]'." }, "CertificateARN": { "Type": "String", "Description": "The Amazon Resource Name (ARN) of the existing AWS IoT certificate." }, "SNSTopicName": { "Type": "String", "Default": "aws-iot-button-sns-topic", "Description": "The name of the Amazon SNS topic for AWS CloudFormation to create." }, "SNSTopicRoleName": { "Type": "String", "Default": "aws-iot-button-sns-topic-role", "Description": "The name of the IAM role for AWS CloudFormation to create. This IAM role allows AWS IoT to send notifications to the Amazon SNS topic." },

    41

    https://console.aws.amazon.com/iot/homehttps://console.aws.amazon.com/cloudformation/

  • AWS IoT AWS IoT AWS CloudFormation

    "EmailAddress": { "Type": "String", "Description": "The email address for the Amazon SNS topic to send information to." } }, "Resources": { "IoTThing": { "Type": "AWS::IoT::Thing", "Properties": { "ThingName": { "Fn::Join" : [ "", [ "iotbutton_", { "Ref": "IoTButtonDSN" } ] ] } } }, "IoTPolicy": { "Type" : "AWS::IoT::Policy", "Properties": { "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Action": "iot:Publish", "Effect": "Allow", "Resource": { "Fn::Join": [ "", [ "arn:aws:iot:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":topic/iotbutton/", { "Ref": "IoTButtonDSN" } ] ] } } ] } } }, "IoTPolicyPrincipalAttachment": { "Type": "AWS::IoT::PolicyPrincipalAttachment", "Properties": { "PolicyName": { "Ref": "IoTPolicy" }, "Principal": { "Ref": "CertificateARN" } } }, "IoTThingPrincipalAttachment": { "Type" : "AWS::IoT::ThingPrincipalAttachment", "Properties": { "Principal": { "Ref": "CertificateARN" }, "ThingName": { "Ref": "IoTThing" }

    42

  • AWS IoT AWS IoT AWS CloudFormation

    } }, "SNSTopic": { "Type": "AWS::SNS::Topic", "Properties": { "DisplayName": "AWS IoT Button Press Notification", "Subscription": [ { "Endpoint": { "Ref": "EmailAddress" }, "Protocol": "email" } ], "TopicName": { "Ref": "SNSTopicName" } } }, "SNSTopicRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "iot.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }, "Path": "/", "Policies": [ { "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sns:Publish", "Resource": { "Fn::Join": [ "", [ "arn:aws:sns:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":", { "Ref": "SNSTopicName" } ] ] } } ] }, "PolicyName": { "Ref": "SNSTopicRoleName" } } ] } }, "IoTTopicRule": {

    43

  • AWS IoT AWS IoT AWS CloudFormation

    "Type": "AWS::IoT::TopicRule", "Properties": { "RuleName": { "Fn::Join": [ "", [ "iotbutton_", { "Ref": "IoTButtonDSN" } ] ] }, "TopicRulePayload": { "Actions": [ { "Sns": { "RoleArn": { "Fn::GetAtt": [ "SNSTopicRole", "Arn" ] }, "TargetArn": { "Ref": "SNSTopic" } } } ], "AwsIotSqlVersion": "2015-10-08", "RuleDisabled": false, "Sql": { "Fn::Join": [ "", [ "SELECT * FROM 'iotbutton/", { "Ref": "IoTButtonDSN" }, "'" ] ] } } } } }}

    b. AWS CloudFormation (https://console.aws.amazon.com/cloudformation/)

    c. AWS AWS IoT (: ())

    d. [Create Stack] e. [Select Template] [Upload a template to Amazon S3] [Browse]

    f. AWSIoTButtonQuickStart.template [Open]

    [Next] g. [Specify Details] [Stack name] AWS CloudFormation (:

    MyAWSIoTButtonStack) h. [CertificateARN] AWS IoT ( ARN ) Amazon

    (ARN) i. [EmailAddress] E j. [IoTButtonDSN] (DSN) AWS IoT

    (: G030JF051234A5BC)k. [SNSTopicName] [SNSTopicRoleName] Amazon

    SNS IAM AWS IoT [Next]

    l. [Options] [Next]

    44

    https://console.aws.amazon.com/cloudformation/

  • AWS IoT

    m. [Review] [I acknowledge that AWS CloudFormation might create IAM resources] [Create]

    n. CREATE_COMPLETE MyAWSIoTButtonStack E AWS IoT Button Press Notification E [Confirm subscription]

    3. AWSIoT

    4. 1 AWS IoT Button Press Notification E E

    5. AWS CloudFormation AWS AWS CloudFormation MyAWSIoTButtonStackMyAWSIoTButtonStack AWS IoT

    a. AWS IoT b. AWS IoT ()

    c. [Actions] [Deactivate] d. AWS IoT [Actions] [Delete]

    e.

    Lambda AWS IoT AWS IoT AWS CloudFormation http://docs.aws.amazon.com/iot/latest/developerguide/iot-button-cloud-formation.html

    45

    http://docs.aws.amazon.com/iot/latest/developerguide/configure-iot.htmlhttp://docs.aws.amazon.com/iot/latest/developerguide/iot-gs.htmlhttp://docs.aws.amazon.com/iot/latest/developerguide/iot-button-cloud-formation.htmlhttp://docs.aws.amazon.com/iot/latest/developerguide/iot-button-cloud-formation.html

  • AWS IoT DynamoDB

    AWS IoT AWS IoT AWS IoT (p. 5)AWS AWS IoT

    AWS IoT SQL SELECT MQTT AWS IoT SQL SELECT MQTT AWS IoT 1 MQTT MQTT MQTT AWS Amazon DynamoDBAWS LambdaAmazon SNSAmazon S3 AWSLambda AWS AWSIoT (p. 178)

    AWS IoT iotbutton/+ AWS IoT

    AWS IoT AWS IoT MQTT MQTT AWS IoT AWS IoT iotbutton/ABCDEFG12345 /

    MQTT AWS IoT (p. 168)

    AWS IoT JSON

    { "serialNumber" : "ABCDEFG12345", "batteryVoltage" : "2000mV", "clickType" : "SINGLE"}

    DynamoDB DynamoDB MQTT DynamoDB

    DynamoDB :

    1. AWS IoT [ACT]

    46

    https://www.amazon.com/All-New-AWS-IoT-Button-Generation/dp/B01KW6YCIMhttps://console.aws.amazon.com/iot/homehttps://console.aws.amazon.com/iot/home

  • AWS IoT DynamoDB

    2. [Rules] [Create]

    3. [Create a rule] [Name] [Description]

    47

  • AWS IoT DynamoDB

    4. [Message source] [Using SQL version] [Attribute] * MQTT

    5. MQTT [Topic filter] iotbutton/your-button-DSNAWS IoT my/topic

    Note

    DSN

    [Condition]

    6. [Set one or more actions] [Add action]

    48

  • AWS IoT DynamoDB

    7. [Select an action] [Insert a message into a DynamoDB table] [Configureaction]

    8. [Configure action] [Create a new resource]

    49

  • AWS IoT DynamoDB

    9. [Amazon DynamoDB] [Create table]

    10. [Create DynamoDB table] [Table name] [Partition key] [SerialNumber] [Add sort key] [ClickType] [Sort key] [String]

    50

  • AWS IoT DynamoDB

    11. [Create] DynamoDB Amazon DynamoDB DynamoDB AWS IoT[Configure action] [Table name]

    12. [Configure action] [Table name] [Hash key value] ${serialNumber}MQTT serialNumber DynamoDB [SerialNumber] [Range key value] ${clickType}clickType [ClickType] [] Payload [Create a new role]

    51

  • AWS IoT DynamoDB

    13. [IAM role name] [Create a new role] [Update role] [Add action]

    14. [Create rule]

    52

  • AWS IoT DynamoDB

    15. [Rules]

    16. AWS IoT MQTT DynamoDB

    53

  • AWS IoT Lambda

    Lambda MQTT Lambda AWS

    AWS IoT (p. 5)Amazon SNSAWS IoT (p. 5) Amazon SNS Lambda MQTT Lambda Lambda

    AWS IoT Lambda AWS IoT MQTT MQTT

    Lambda Lambda :

    1. AWS Lambda [Get Started Now] Lambda [Create a Lambda function]

    54

    https://www.amazon.com/dp/B01C7WE5WMhttps://console.aws.amazon.com/lambda/home

  • AWS IoT Lambda

    2. [Select blueprint] [Filter] hello-world [hello-world]

    3. [Configure triggers] Lambda [AWS IoT]

    55

  • AWS IoT Lambda

    4. [Device Serial Number] (DSN) DSN AWS IoT AWS IoT [Generate certificate and keys] 6

    56

  • AWS IoT Lambda

    5. PEM

    AWS IoT 6. [Enable trigger] [Next]

    57

  • AWS IoT Lambda

    7. [Configure function] Lambda [Runtime] [Node.js 6.10]

    8. [Lambda function code]

    console.log('Loading function'); // Load the AWS SDK var AWS = require("aws-sdk"); // Set up the code to call when the Lambda function is invoked exports.handler = (event, context, callback) => { // Load the message passed into the Lambda function into a JSON object var eventText = JSON.stringify(event, null, 2); // Log a message to the console, you can view this text in the Monitoring tab in the Lambda console or in the CloudWatch Logs console console.log("Received event:", eventText); // Create a string extracting the click type and serial number from the message sent by the AWS IoT button var messageText = "Received " + event.clickType + " message from button ID: " + event.serialNumber; // Write the string to the console console.log("Message to send: " + messageText); // Create an SNS object var sns = new AWS.SNS(); // Populate the parameters for the publish operation // - Message : the text of the message to send // - TopicArn : the ARN of the Amazon SNS topic to which you want to publish var params = { Message: messageText, TopicArn: "arn:aws:sns:us-east-1:123456789012:MyIoTButtonSNSTopic" }; sns.publish(params, context.done); };

    58

  • AWS IoT Lambda

    Note

    TopicArn Amazon SNS ARN 9. [Lambda function handler and role] [Role]

    [Create a custom role] IAM Lambda Lambda IAM

    Amazon SNS :

    a. [View Policy Document]

    b. [Edit]

    59

  • AWS IoT Lambda

    c.

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "sns:Publish" ], "Resource": "arn:aws:sns:us-east-1:123456789012:MyIoTButtonSNSTopic" } ]}

    Amazon SNS

    Note

    2 Resource Amazon SNS ARN

    10. [Allow]

    60

  • AWS IoT Lambda

    11. [Advanced settings] [Next]

    12. [Review] [Create function]

    61

  • AWS IoT Lambda

    Lambda Lambda :

    1. [Actions] [Configure test event]

    2. JSON [Input test event] [Save and test]

    62

  • AWS IoT Lambda

    { "serialNumber": "ABCDEFG12345", "clickType": "SINGLE", "batteryVoltage": "2000 mV"}

    3. AWS Lambda [Log output] Lambda

    63

  • AWS IoT Lambda

    Lambda Lambda Lambda

    1. AWS IoT [ACT]

    2. [Rules] [Create]

    64

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

  • AWS IoT Lambda

    3.

    4.

    65

  • AWS IoT Lambda

    5. [Set one or more actions] [Add action]

    6. [Select an action] [Invoke a Lambda function passing the message data] [Configure action]

    66

  • AWS IoT Lambda

    7. [Function name] Lambda [Add action]

    8. [Create rule] Lambda

    Lambda AWS IoT (p. 5)

    67

  • AWS IoT Lambda

    AWS IoT Amazon SNS

    Wi-Fi Amazon SNS Lambda SMS

    (SINGLE DOUBLE)

    IOT BUTTON> { "serialNumber" : "ABCDEFG12345", "clickType" : "SINGLE", "batteryVoltage" : "2000 mV"}

    AWS IoT MQTT

    1. AWS IoT [Test]

    2. [Publish] [MQTT client] [Specify a topic] iotbutton/ABCDEFG12345

    [Payload] JSON [Publish to topic]

    { "serialNumber" : "ABCDEFG12345", "clickType" : "SINGLE", "batteryVoltage" : "2000 mV"}

    68

    https://www.amazon.com/dp/B01C7WE5WMhttps://console.aws.amazon.com/iot/home

  • AWS IoT Amazon SNS

    3.

    Amazon SNS Amazon SNS AWS IoT Amazon SNS

    SNS :

    1. AWS IoT [ACT]

    2. [Rules] [Create]

    69

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

  • AWS IoT Amazon SNS

    3.

    4. [Message source] [Attribute] *, topic(3)[Topic filter] $aws/things/+/shadow/update/accepted (+)

    70

  • AWS IoT Amazon SNS

    5. [Set one or more actions] [Add action]

    6. [Select an action] [Send a message as an SNS push notification] [Configure action] ()

    71

  • AWS IoT Amazon SNS

    7. [Create new topic]

    8. SNS [Create]

    72

  • AWS IoT Amazon SNS

    9. AWS IoT [SNS target] SNS [Message format] [JSON]

    10. [IAM role name] [Create a new role]

    73

  • AWS IoT Amazon SNS

    11. [Create a new role]

    74

  • AWS IoT Amazon SNS

    12. [Add action]

    75

  • AWS IoT Amazon SNS

    13. [Create rule]

    SNS AWS IoT Shadow AWS IoT Device Shadow $aws/things/MySNSThing/shadow/update/accepted SNS

    76

  • AWS IoT Raspberry Pi

    AWS IoT SDK AWS IoT Device SDK AWS IoT AWS IoT Device SDK IoT

    AWS IoT Raspberry Pi AWS IoT Embedded C SDK Device SDK for JavaScript AWS IoT AWS IoT SDK

    Raspberry Pi (p. 77) AWS IoT Embedded C SDK (p. 86) AWS IoT Device SDK for JavaScript (p. 89)

    Raspberry Pi AWS IoT Raspberry Pi

    Raspberry Pi

    Raspberry Pi Raspberry Pi

    Chrome FirefoxIceweasel

    Iceweasel Linux Wiki

    Raspberry Pi 2 Model B Raspbian Wheezy Raspbian Jessie Iceweasel

    AWS IoT 1. Raspberry Pi 2. AWS https://aws.amazon.com/iot AWS IoT

    [Welcome] [Get started]

    77

    https://www.raspberrypi.org/help/quick-start-guide/http://elinux.org/RPi_IceWeasel#Installing_the_softwarehttps://www.raspberrypi.org/https://www.raspberrypi.org/downloads/https://www.raspberrypi.org/downloads/raspbian/http://elinux.org/RPi_IceWeasel#Installing_the_softwarehttps://aws.amazon.com/iot

  • AWS IoT AWS IoT

    3. AWS IoT [Welcome to the AWS IoT Console] [Manage] [Things]

    4. [You don't have any things yet] [Register a thing] ([Create] )

    78

  • AWS IoT

    AWS Device Shadow AWS IoT

    1. [Create thing]

    2. [Details] [Interact]

    79

  • AWS IoT

    3. REST API [Security]

    4. [Create certificate] X.509

    80

  • AWS IoT

    5. deviceSDK CA deviceSDK [Activate] X.509 [Attach a policy]

    6. [Create new policy]

    81

  • AWS IoT

    7. [Create a policy] [Name] [Action] iot:*[Resource ARN] *[Allow] Raspberry Pi AWS IoT

    8. [Create]

    82

  • AWS IoT

    9. [Policies]

    10. [Security] [Certificates]

    83

  • AWS IoT

    11. [...] [Attachpolicy]

    12. [Attach policies to certificate(s)] [Attach]

    84

  • AWS IoT

    13. [...] [Attach thing]

    14. [Attach things to certificate(s)] Raspberry Pi [Attach]

    85

  • AWS IoT AWS IoT Embedded C SDK

    AWS IoT Embedded C SDK AWS IoT Embedded C SDK 1. GitHub AWS IoT Device SDK for C

    git clone https://github.com/aws/aws-iot-device-sdk-embedded-C.git -brelease

    2. AWS IoT Embedded C SDK GitHub deviceSDK/external_libs

    AWS IoT Embedded C SDK subscribe_publish_sample

    1. deviceSDK/certs CA

    CA CA deviceSDK/certs

    Note

    CA CA

    2. deviceSDK/sample_apps/subscribe_publish_sample REST API AWS CLI

    86

    https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem

  • AWS IoT

    aws iot describe-endpoint URL AWS IoT [Registry] [Things] Raspberry Pi [Details] [Interact] REST APIendpoint .com

    3. aws_iot_config.h [//Get from console]

    AWS_IOT_MQTT_HOST

    AWS_IOT_MY_THING_NAME

    AWS_IOT_ROOT_CA_FILENAME

    CA AWS_IOT_CERTIFICATE_FILENAME

    AWS_IOT_PRIVATE_KEY_FILENAME

    (:

    // Get from console// =================================================#define AWS_IOT_MQTT_HOST "a22j5sm6o3yzc5.iot.us-east-1.amazonaws.com"#define AWS_IOT_MQTT_PORT 8883#define AWS_IOT_MQTT_CLIENT_ID "MyRaspberryPi"#define AWS_IOT_MY_THING_NAME "MyRaspberryPi"#define AWS_IOT_ROOT_CA_FILENAME "root-CA.crt"#define AWS_IOT_CERTIFICATE_FILENAME "4bbdc778b9-certificate.pem.crt"#define AWS_IOT_PRIVATE_KEY_FILENAME "4bbdc778b9-private.pem.key"// =================================================

    87

  • AWS IoT

    1. makefile subscribe_publish_sample_app

    make -f Makefile

    2. subscribe_publish_sample_app

    Raspberry Pi AWS IoT Device SDK for C AWS IoT

    88

  • AWS IoT AWS IoT Device SDK for JavaScript

    AWS IoT Device SDK for JavaScript AWS IoT Device SDK for Node.js npm Node npm

    AWS IoT Device SDK for JavaScript AWS IoT Device SDK for JavaScript Raspberry Pi Node npm

    Note

    Raspberry Pi Raspberry Pi

    1. Node

    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

    2. Node

    sudo apt-get install nodejs

    3. npm -v npm npm

    sudo apt-get install npm

    4. Node npm

    node -v

    89

    https://www.raspberrypi.org/documentation/configuration/localisation.md

  • AWS IoT AWS IoT Device SDK for JavaScript

    npm -v

    AWS IoT Device SDK for JavaScript AWS IoT Device SDK for JavaScript/Node.js Raspberry Pi ~/deviceSDK npm SDK

    npm install aws-iot-device-sdk

    ~/deviceSDK node_modules

    AWS IoT Device SDK for JavaScript

    ~/deviceSDK/node_modules/aws-iot-device-sdk/examples/lib/cmdline.js (privateKey) (clientCert)CA (caCert) (:

    default: { region: 'us-east-1', clientId: clientIdDefault, privateKey: '4bbdc778b9-private.pem.key', clientCert: '4bbdc778b9-certificate.pem.crt', caCert: 'root-CA.crt, testMode: 1, reconnectPeriod: 3 * 1000, /* milliseconds */ delay: 4 * 1000 /* milliseconds */

    90

  • AWS IoT

    };

    node examples/.js -f -H .iot..amazonaws.com

    ~/deviceSDK/node_modules/aws-iot-device-sdk/ ~/deviceSDK/certs/ Raspberry Pi REST -H

    -h

    node examples/.js -h

    GitHub AWS IoT Device SDK for JavaScript Readme Readme

    --configuration-file (-F) (JSON ) (:

    { "host": "a22j5sm6o3yzc5.iot.us-east-1.amazonaws.com", "port": 8883, "clientId": "MyRaspberryPi", "thingName": "MyRaspberryPi", "caCert": "root-CA.crt", "clientCert": "4bbdc778b9-certificate.pem.crt", "privateKey": "4bbdc778b9-private.pem.key"}

    Raspberry Pi AWS IoT SDK for JavaScript AWS IoT

    91

    https://github.com/aws/aws-iot-device-sdk-js#certificates

  • AWS IoT

    AWS IoT AWS IoT "" () AWS IoT ()

    JSON Registry

    { "version": 3, "thingName": "MyLightBulb", "defaultClientId": "MyLightBulb", "thingTypeName": "LightBulb", "attributes": { "model": "123", "wattage": "75" }}

    ()

    MQTT ID MQTT ID Device Shadow MQTT ID Shadows IoT

    AWS IoT

    AWS IoT AWS CLI CLI Registry

    CLI AWS IoT CreateThing

    $ aws iot create-thing --thing-name "MyLightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"

    CreateThing ARN

    { "thingArn": "arn:aws:iot:us-east-1:123456789012:thing/MyLightBulb",

    92

  • AWS IoT

    "thingName": "MyLightBulb" "thingId": "12345678abcdefgh12345678ijklmnop12345678"}

    ListThings

    $ aws iot list-things{ "things": [ { "attributes": { "model": "123", "wattage": "75" }, "version": 1, "thingName": "MyLightBulb" }, { "attributes": { "numOfStates":"3" }, "version": 11, "thingName": "MyWallSwitch" } ]}

    DescribeThing

    $ aws iot describe-thing --thing-name "MyLightBulb"{ "version": 3, "thingName": "MyLightBulb", "thingArn": "arn:aws:iot:us-east-1:123456789012:thing/MyLightBulb", "thingId": "12345678abcdefgh12345678ijklmnop12345678" "defaultClientId": "MyLightBulb", "thingTypeName": "StopLight", "attributes": { "model": "123", "wattage": "75" }}

    ListThings

    $ aws iot list-things --thing-type-name "LightBulb"

    { "things": [ { "thingTypeName": "LightBulb", "attributes": { "model": "123",

    93

  • AWS IoT

    "wattage": "75" }, "version": 1, "thingName": "MyRGBLight" }, { "thingTypeName": "LightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1, "thingName": "MySecondLightBulb" } ]}

    ListThings

    $ aws iot list-things --attribute-name "wattage" --attribute-value "75"

    { "things": [ { "thingTypeName": "StopLight", "attributes": { "model": "123", "wattage": "75" }, "version": 3, "thingName": "MyLightBulb" }, { "thingTypeName": "LightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1, "thingName": "MyRGBLight" }, { "thingTypeName": "LightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1, "thingName": "MySecondLightBulb" } ]}

    UpdateThing

    $ aws iot update-thing --thing-name "MyLightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"150\", \"model\":\"456\"}}"

    94

  • AWS IoT

    UpdateThing DescribeThing

    $ aws iot describe-thing --thing-name "MyLightBulb"{ "attributes": { "model": "456", "wattage": "150" }, "version": 2, "thingName": "MyLightBulb"}

    DeleteThing

    $ aws iot delete-thing --thing-name "MyThing"

    AWS IoT X.509 Registry AttachThingPrincipal

    $ aws iot attach-thing-principal --thing-name "MyLightBulb" --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847"

    AttachThingPrincipal

    DetachThingPrincipal

    $ aws iot detach-thing-principal --thing-name "MyLightBulb" --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847"

    DetachThingPrincipal

    Registry LightBulb LightBulb () LightBulb ( LightBulb ) LightBulb

    50

    95

  • AWS IoT

    3 1 1

    1

    CreateThingType

    $ aws iot create-thing-type

    --thing-type-name "LightBulb" --thing-type-properties "thingTypeDescription=light bulb type, searchableAttributes=wattage,model"

    CreateThingType ARN

    { "thingTypeName": "LightBulb", "thingTypeArn": "arn:aws:iot:us-west-2:123456789012:thingtype/LightBulb"}

    ListThingTypes

    $ aws iot list-thing-types

    ListThingTypes AWS

    { "thingTypes": [ { "thingTypeName": "LightBulb", "thingTypeProperties": { "searchableAttributes": [ "wattage", "model" ], "thingTypeDescription": "light bulb type" }, "thingTypeMetadata": { "deprecated": false, "creationDate": 1468423800950 } } ]}

    DescribeThingType

    96

  • AWS IoT

    $ aws iot describe-thing-type --thing-type-name "LightBulb"

    DescribeThingType

    { "thingTypeName": "LightBulb", "thingTypeProperties": { "searchableAttributes": [ "wattage", "model" ], "thingTypeDescription": "light bulb type" }, "thingTypeMetadata": { "deprecated": false, "creationDate": 1468423800950, }}

    CreateThing

    $ aws iot create-thing --thing-name "MySecondLightBulb" --thing-type-name "LightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"

    UpdateThing

    $ aws iot update-thing --thing-name "MyLightBulb" --thing-type-name "StopLight" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"

    UpdateThing

    DeprecateThingType

    $ aws iot deprecate-thing-type --thing-type-name "myThingType"

    DescribeThingType

    $ aws iot describe-thing-type --thing-type-name "StopLight":

    { "thingTypeName": "StopLight", "thingTypeProperties": { "searchableAttributes": [ "wattage", "numOfLights",

    97

  • AWS IoT

    "model" ], "thingTypeDescription": "traffic light type", }, "thingTypeMetadata": { "deprecated": true, "creationDate": 1468425854308, "deprecationDate": 1468446026349 }}

    --undo-deprecate DeprecateThingType CLI

    $ aws iot deprecate-thing-type --thing-type-name "myThingType" --undo-deprecate

    DescribeThingType CLI

    $ aws iot describe-thing-type --thing-type-name "StopLight":

    { "thingTypeName": "StopLight", "thingTypeArn": "arn:aws:iot:us-east-1:123456789012:thingtype/StopLight", "thingTypeId": "12345678abcdefgh12345678ijklmnop12345678" "thingTypeProperties": { "searchableAttributes": [ "wattage", "numOfLights", "model" ], "thingTypeDescription": "traffic light type" }, "thingTypeMetadata": { "deprecated": false, "creationDate": 1468425854308, }}

    DeleteThingType

    $ aws iot delete-thing-type --thing-type-name "StopLight"

    Note

    5

    98

  • AWS IoT

    () () (

    ) ( 1

    ) (AWS IoT (p. 401)) (

    (p. 270))

    (

    ) 10 ( 2

    )

    AWS IoT

    CreateThingGroup

    $ aws iot create-thing-group --thing-group-name LightBulbs

    CreateThingGroup ID ARN

    { "thingGroupName": "LightBulbs", "thingGroupId": "abcdefgh12345678ijklmnop12345678qrstuvwx", "thingGroupArn": "arn:aws:iot:us-west-2:123456789012:thinggroup/LightBulbs"

    99

  • AWS IoT

    }

    $ aws iot create-thing-group --thing-group-name RedLights --parent-group-name LightBulbs

    CreateThingGroup ID ARN

    { "thingGroupName": "RedLights", "thingGroupId": "abcdefgh12345678ijklmnop12345678qrstuvwx", "thingGroupArn": "arn:aws:iot:us-west-2:123456789012:thinggroup/RedLights",}

    Important

    1 1 100 7 5