cloud tutorial: aws iotlu/cse520s/slides/cloud... · 2020-01-16 · step 1: create a virtual...

47
Cloud Tutorial: AWS IoT CSE 520S Spring, Jan. 16, 2020 Ruixuan Dai

Upload: others

Post on 25-Feb-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

CloudTutorial:AWSIoT

CSE520SSpring,Jan.16,2020RuixuanDai

Page 2: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

XaaS:BasicsinCloudComputing

Page 3: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

CloudComputing

1/16/20 3

Ø Cloud computing provides shared pool of configurable computing resource to end users on demand

Ø  Three service modelsq  IaaS (Infrastructure as a Service): virtual machines, storage,

network …

q PaaS (Platform as a Service): execution runtime, middleware, web server, database, development tool …

q  SaaS (Software as a Service): email, virtual desktop, games …

Page 4: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

CloudServices:On-premiseSoftware

Ø  Traditional

Ø  installed and runs on personal computer

Ø  You Manage and Deployq  Hardwareq  OSq  Software

Ø  Exampleq  This presentation

1/16/20 4

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

YouManage

Page 5: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

InfrastructureasaService(IaaS)Ø  IaaS

q  "physical server box”q  Virtual Machine•  Memory•  Storage•  CPU•  Network

Ø  Exampleq  AWS EC2q  AWS EFS

Ø Use caseq  Build up you VM cluster

1/16/20 5

YouManage

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

ServiceProviderManages

WebService

Page 6: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

PlatformasaService(PaaS)

Ø  PaaSq  You get a framework

q  Host Application

q  Tools

Ø  Exampleq  AWS IoT

Ø Use caseq  Build up you’re smart A/C

controller

1/16/20 6

YouManage

ServiceProviderManages

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

Page 7: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

PaaSExample:AWSIoT

1/16/20 7

Tools

FrameworkTheessenceisMESSAGINGMIDDLEWARE

Sendmessagesbetweensensorsandservers…

Page 8: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

SoftwareasaService(SaaS)

Ø  SaaSq  You get a whole solution

Ø  Exampleq  Gmailq  Dropbox

q  Office365

1/16/20 8

ServiceProviderManages

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

Page 9: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

XaaS:ARecap

1/16/20 9

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

YouManage

YouManage

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

ServiceProviderManages

YouManage

ServiceProviderManages

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

ServiceProviderManages

APP

Data

Runtime

Middleware

OS

Virtualization

Server

Storage

Network

On-Premise IaaS PaaS SaaS

Page 10: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Tutorial:Hello!AWSIoT!!

Page 11: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Internet-of-Things

1/16/20 11

Ø  Things (Devices)q  Many of them•  Different Types

•  Isolated Systems

q  Data and Command•  Sensing the world

•  Give Response

q  Challenge•  United: Connected + Communication

•  Smart: Data Analytics + Strategy

Source:https://aws.amazon.com/iot-platform/http://www.brain-smart.net/smart-brain-health-blog/page/2/#axzz4W4oSp8a6

Page 12: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Solution:AWSIoT

1/16/20 12

United:Connect+Communication Smart:OtherCloudServiceDataStorageMachineLearning

Source:https://aws.amazon.com/iot-platform/

Stated:“ThingShadow”

Page 13: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Tutorial:HelloAWSIoT!

1/16/20 13Source:https://aws.amazon.com/iot-platform/

Publish

AmazonSNS

Forward

Subscribe TemperaturesensorPeriod:5s(0.2Hz)

Messagemiddleware

Page 14: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Pointers

Ø Amazon IoTq  http://docs.aws.amazon.com/iot/latest/developerguide/what-is-

aws-iot.html

Ø  Raspberry Piq  https://www.raspberrypi.org/

Ø  Resource list for course projectsq  http://cps.cse.wustl.edu/index.php/List_of_Projects

Ø Apply for $40 credits for Amazon AWS q  https://aws.amazon.com/education/awseducate/apply/

14

Page 15: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

GetintoAWSManageConsole

Ø Create your own AWS accountØ  Sign In IoT Manage Console

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

1/16/20 15

Page 16: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Step1:CreateaVirtual"Thing”

1/16/20 16

AWSIoT

Virtual“Thing”/Shadow

Ø A Thing in AWS IoT has a “shadow”q  a JSON document that is used to store and retrieve

current state information for a device.•  E.g. Battery level, Connectivity, data

q  Shadow is a special topic in AWS IoT

Ø Certificates and policyq Authentication, Securityq Permission and roles

A“Dashboard”toshowsomeinfo

Certificates->yourIDPolicy->yourpermissionbook

Page 17: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Createathing

Ø  1. AWS IoT Menu•  Things è Create

Ø  2. Give a name

1/16/20 17

Page 18: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

18

Page 19: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

19

Page 20: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

20

Thekeysandcertwillbeusedlater

Page 21: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

CreatePolicy

Ø A policy is attached to a key/certq  It tells what this key/cert can do

21

Page 22: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

22

Page 23: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

23

Thisisthepolicyyoucreated

Page 24: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

AttachPolicy

Ø Attach Policy to the key/certq  A policy tells what this key/cert can do

24

Clickthecert

Page 25: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

25

Page 26: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

26

Page 27: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

AWSThingsSummary

27

q  Shadow: Store/retrieve some informationq Certificate: authenticate the deviceq Policy: define the roles/permissions of the

certificate

Page 28: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Let’stestitonline!

Page 29: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

BasicInteract:Publishtothe“Shadow”

Ø Get your “Shadow”q  In your Thing Page

1/16/20 29

ShadowTopic

Page 30: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Findyour“Shadow”Topic

Ø  Topic: can be seen as the “address”

1/16/20 30

ShadowTopic

Page 31: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Ø Using Embedded Test Client to Testq  In AWS IoT Page

1/16/20 31

YourShadowTopicTopicMessage

Page 32: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

ShadowMessage

{ "state": { "reported":{

"time":"13:45", "temperature":"25"} },

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

32

AShadowMessageisaJSONobject.Shadowmessagehasstrictformats.

Pleaseseehttps://docs.aws.amazon.com/iot/latest/developerguide/device-

shadow-document-syntax.html

Page 33: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

UpdateShadow

Ø  In your “Thing” Page

33

Page 34: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

BasicInteract:Subscribe/Publish

1/16/20 34

Ø  You can define your own TopicØ Once you have a subscriber that is subscribed to the topic,

the subscriber can receive the message

Page 35: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

BasicInteract:Subscribe/Publish

1/16/20 35

Ø  You can define your own TopicØ Once you have a subscriber that is subscribed to the topic,

the subscriber can receive the message

a“Topic”

Iamgoingtopublishatweet.

“Todayisbeautiful”

Twitteraccount

ReceivedmessagefromTrump:“Todayisbeautiful”

Subscriber

Publisher

Page 36: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

TemperaturesensorPeriod:15s(4Hz)

Step2:Connecta“Physical”Device

1/16/20 36

AWSIoT

Virtual“Thing”/Shadow

Attach

Certificate

Policy Copy

AWSSD

KClient

AWSIoTSDK

Page 37: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

ConnectyourDevice Ø Copy certificates to your physical

thingsq  Note: through scp utilityq  Downloaded before!

Ø Choose your AWS SDK (support MQTT)q  Node JSq  Python (pip install AWSIoTPythonSDK )q  Javaq  …

Ø  Set up your client with SDK and the certificates

1/16/20 37

Page 38: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

SomeNotes

Ø  1. Copy the certificates/keys to your real thing

Ø  2. You will need the endpoint and port (8883)

1/16/20 38

Host(Endpoint)

Modifythecode

Page 39: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

SDKandDemoCodes

Ø  https://github.com/aws/aws-iot-device-sdk-pythonØ  https://github.com/aws/aws-iot-device-sdk-python/blob/

master/samples/basicPubSub/basicPubSub.py

39

Page 40: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

More:RuleEngine,LinkwithSNSservices

Ø  Simple Notification Service

1/16/20 40

Publish

AmazonSNS

AWSIoT

Virtual“Thing”/Shadow

Forward

Topic:CSE521_Tutorial

Subscribe

Subscribe

AWSEC2t2.micro

Page 41: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

CreateaRuleinAmazonIoT

Ø Add a query to filter your interesting topic (event)

Ø Add an Action:q  Forward this message to SNS

q  Specify Dest ARN

q  Enable Rule

1/16/20 41

Page 42: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

NotificationonSMS&Email

1/16/20 42

Page 43: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

OneMoreThing:AccountSecurity

Ø DON’T UPLOAD YOUR KEY PUBLICLY!!!

1/16/20 43

TimetoOpenSource!

Source:WeChatSubscriptions: 西乔《神秘的程序员们 39》GeekLifeChpt39.

Page 44: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Whatif…$50,000AWSBill!

1/16/20 44Source:https://www.quora.com/My-AWS-account-was-hacked-and-I-have-a-50-000-bill-how-can-I-reduce-the-amount-I-need-to-pay

Page 45: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Project0:AWSIoTØ  Create Your AWS accountØ  Setup your things with certificates and policyØ  Publish and subscribe a topic

q  Update your thing’s Shadow with AWS IoT Test Console•  See tutorial

q  Use your computer as a “Thing” to update your thing’s Shadow •  Install AWS IoT SDK, copy the certs, modify the code•  Publish message to your Shadow Topic from your computer

q  Publish and Subscribe on your computer•  Publish a message to a topic in one client from your PC•  Subscribe to the same topic in another client from your PC•  Hints: the “clientID” cannot be the same for the two client. The two

clients can share the same certs. You can use the shadow as the topic.•  (You should see one terminal sends massage, and another terminal

receives that message)Ø  Email your results (inline with some screenshots, you don’t need to

write a report) to [email protected]

45

Page 46: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Someprojectexamples

Ø Gesture recognition with smartwatchq  Recognize the specific gesture to control the light

Ø  Smart pet feederq  Food dispenser with schedules and smart control

Ø  Smart mirrorq  Show personalized info in the mirror

46

Sensing,Connecting,Smart

Ifyouhaveanyquestionabouttheproject,feelfreetosendmeanEmail

Page 47: Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual "Thing” 1/16/20 16 AWS IoT Virtual “Thing” / Shadow Ø A Thing in AWS IoT has a

Thanks!

RuixuanDai