Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual...

Post on 25-Feb-2020

0 views 0 download

Transcript of Cloud Tutorial: AWS IoTlu/cse520s/slides/cloud... · 2020-01-16 · Step 1: Create a Virtual...

CloudTutorial:AWSIoT

CSE520SSpring,Jan.16,2020RuixuanDai

XaaS:BasicsinCloudComputing

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 …

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

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

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

PaaSExample:AWSIoT

1/16/20 7

Tools

FrameworkTheessenceisMESSAGINGMIDDLEWARE

Sendmessagesbetweensensorsandservers…

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

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

Tutorial:Hello!AWSIoT!!

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

Solution:AWSIoT

1/16/20 12

United:Connect+Communication Smart:OtherCloudServiceDataStorageMachineLearning

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

Stated:“ThingShadow”

Tutorial:HelloAWSIoT!

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

Publish

AmazonSNS

Forward

Subscribe TemperaturesensorPeriod:5s(0.2Hz)

Messagemiddleware

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

GetintoAWSManageConsole

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

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

1/16/20 15

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

Createathing

Ø  1. AWS IoT Menu•  Things è Create

Ø  2. Give a name

1/16/20 17

18

19

20

Thekeysandcertwillbeusedlater

CreatePolicy

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

21

22

23

Thisisthepolicyyoucreated

AttachPolicy

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

24

Clickthecert

25

26

AWSThingsSummary

27

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

certificate

Let’stestitonline!

BasicInteract:Publishtothe“Shadow”

Ø Get your “Shadow”q  In your Thing Page

1/16/20 29

ShadowTopic

Findyour“Shadow”Topic

Ø  Topic: can be seen as the “address”

1/16/20 30

ShadowTopic

Ø Using Embedded Test Client to Testq  In AWS IoT Page

1/16/20 31

YourShadowTopicTopicMessage

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

UpdateShadow

Ø  In your “Thing” Page

33

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

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

TemperaturesensorPeriod:15s(4Hz)

Step2:Connecta“Physical”Device

1/16/20 36

AWSIoT

Virtual“Thing”/Shadow

Attach

Certificate

Policy Copy

AWSSD

KClient

AWSIoTSDK

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

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

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

More:RuleEngine,LinkwithSNSservices

Ø  Simple Notification Service

1/16/20 40

Publish

AmazonSNS

AWSIoT

Virtual“Thing”/Shadow

Forward

Topic:CSE521_Tutorial

Subscribe

Subscribe

AWSEC2t2.micro

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

NotificationonSMS&Email

1/16/20 42

OneMoreThing:AccountSecurity

Ø DON’T UPLOAD YOUR KEY PUBLICLY!!!

1/16/20 43

TimetoOpenSource!

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

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

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 dairuixuan@wustl.edu

45

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

Thanks!

RuixuanDai