Cloud Tutorial: Aws Iot: Cse 521S Fall Sep. 17, 2020 Ruixuan (Corey) Dai

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 47

Cloud Tutorial: AWS IoT

CSE 521S
Fall Sep.
17, 2020
Ruixuan
(Corey) Dai
XaaS: Basics in Cloud Computing
Cloud Computing
 Cloud computing provides shared pool of configurable
computing resource to end users on demand
 Three service models
 IaaS (Infrastructure as a Service): virtual machines, storage,
network …

 PaaS (Platform as a Service): execution runtime, middleware,


web server, database, development tool …

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

9/17/20 3
Cloud Services: On-premise Software
 Traditiona APP
l
 installed and runs on Data
personal computer Runtime

 You Manage and Middleware

You Manage
Deploy
OS
 Hardware
 OS Virtualization
 Software
Server
 Example
 This presentation Storage

Network

9/17/20 4
Infrastructure as a Service (IaaS)
 Iaa
APP
S "physical server box” Web
 Virtual Machine Service Data

You Manage
• Memory
Runtime
• Storage
• CPU Middleware
• Network
OS
 Example

Service Provider Manages


 AWS EC2 Virtualization
 AWS EFS
Server

 Use case Storage


 Build up you VM Network
cluster
9/17/20 5
Platform as a Service (PaaS)
 PaaS

You Manage
APP
 You get a framework
 Host Data

Application Runtime
 Tools
Middleware

Service Provider Manages


 Example
OS
 AWS IoT
Virtualization

 Use case Server


 Build up you’re smart
Storage
A/C controller
Network

9/17/20 6
PaaS Example: AWS IoT

Tools

Framewor
k The essence is MESSAGING MIDDLEWARE
9/17/20 Send messages between sensors and servers… 7
Software as a Service (SaaS)
 SaaS APP
 You get a whole solution
Data

Service Provider Manages


Runtime

 Exampl Middleware
e
OS
 Gmail
 Drop Virtualization
box
Server
 Offic
e365 Storage

Network

9/17/20 8
XaaS: A Recap
On-Premise IaaS PaaS SaaS

You Manage
APP APP APP APP

Data Data Data Data

You Manage
Runtime Runtime Runtime Runtime

Service Provider Manages


Middleware Middleware Middleware

Service Provider Manages


Middleware
You Manage

OS OS OS OS
Service Provider Manages
Virtualization Virtualization Virtualization Virtualization

Server Server Server Server

Storage Storage Storage Storage

Network Network Network Network


9/17/20 9
Tutorial: Hello! AWS IoT!!
Internet-of-Things
 Internet-of-Things
 Devices
• Different Types
 Sensors, actuators

 Data and Command


• Sensing the world
• Give Response

 Challenge
• United:
Connected +
Communication
• Smart: Data
9/17/20 Analytics + Source: https://aws.amazon.com/iot-platform/ 11
http://www.brain-smart.net/smart-brain-health-blog/page/2/#axzz4W4oSp8a6
Solution: AWS IoT

United: Connect + Communication Smart: Other Cloud Service


Data Storage
Stated: “Thing Shadow” Machine Learning

9/17/20 Source: https://aws.amazon.com/iot-platform/ 12


Tutorial: Hello AWS IoT!
 Key concepts:
 Publisher (e.g. Sensor), Subscriber (e.g. Server),
Topic
• Topic is used to identify the message.
 Not a traditional “peer-to-peer” communication.

Publish to a topic Forward

Amazon SNS
Subscribe to a topic
Temperature sensor
Period: 5s (0.2Hz)
Message middleware
9/17/20 Source: https://aws.amazon.com/iot-platform/ 13
Basic Interact: Subscribe/Publish
 You can define your own Topic (Twitter Account)
 Subscriber can receive the message you published to your
topic
I am going to
publish a
tweet.
“Today is
Tw beautiful ”
“P ee
ow i be” ub t
ll r lis
F o u b sc h”
“s Twitter account
a “Topic”

Received message
Subscriber from Trump:
“Today is beautiful”
Publisher
9/17/20 14
Resources
 Amazon IoT
 http://docs.aws.amazon.com/iot/latest/developerguide/what-is-
aws-iot.html
 Raspberry Pi
 https://www.raspberrypi.org/

 Resource list for course projects


 http://cps.cse.wustl.edu/index.php/List_of_Projects

 Apply for $40 credits for Amazon AWS


 https://aws.amazon.com/education/awseducate/apply/

15
Get into AWS Manage Console
 Create your own AWS account
 Sign In IoT Manage Console
 https://aws.amazon.com/iot/

9/17/20 16
Step 1: Create a Virtual "Thing”
 Virtual “Thing”: a virtual copy of your thing
 A Thing in AWS IoT has a “shadow”
• a JSON document that is used to store and retrieve current
state information for a device.
 E.g. Battery level, Connectivity, data
A “Dashboard” to show some info
 Shadow is a special topic in AWS IoT

 Certificates and policy AWS IoT


 Authentication, Security
 Permission and roles

Certificates -> your ID Virtual “Thing”


Policy -> your permission book / Shadow

9/17/20 17
Create a thing
 1. AWS IoT Menu
• Things  Create
 2. Give a name

9/17/20 18
19
20
The keys and cert will be used
later

21
Create Policy
 A policy is attached to a key/cert
 It tells what this key/cert can do

22
Here, we grant it all permissions for demo!

23
This is the policy you created

24
Attach Policy
 Attach Policy to the key/cert
 A policy tells what this key/cert can do

Click the cert you


just created

25
26
27
Now, you have a virtual thing on AWS!

28
AWS Things Summary
 Certificate: authenticate the device
 Policy: define the roles/permissions of the
certificate
 Virtual copy of the thing (Shadow): Store/retrieve
some information

29
Let’s test it online!
Basic Interact: Publish to the “Shadow”
 Get your “Shadow” Shadow is a special topic
 In your Thing Page

Shadow Topic

9/17/20 31
Find your “Shadow” Topic
 Topic: can be seen as the “address”
Shadow Topic:
$aws/things/cse521/shadow/update

9/17/20 https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-mqtt.html?icmpid=docs_iot_console 32
 Using Embedded Test Client to Test Your Shadow Topic
 In AWS IoT Page

Topic Message

9/17/20 33
Shadow Message
{ "state": {
"reported":{
"welcome": "CSE521s",
"time":"13:45",
"temperature":"25"}
},
"message": "Hello from CSE521s
console"}

A Shadow Message is a JSON object.


Shadow message has strict formats.
Please see
https://docs.aws.amazon.com/iot/latest/developerguide/device-
shadow-document-syntax.html
34
Update Shadow
 In your “Thing”
Page

35
Basic Interact: Subscribe/Publish
 You can define your own Topic
 Once you have a subscriber that is subscribed to the topic,
the subscriber can receive the message

9/17/20 36
Step 2: Connect a “Physical” Device

AWS IoT SDK AWS SDK Client AWS IoT

Certificate

Virtual “Thing” Attach


/ Shadow

Temperature senso r
Period: 5s (0.2Hz)
Copy Policy

9/17/20 37
Connect your Device
 Copy certificates to your physical things
 Downloaded before!

 Choose your AWS SDK (support MQTT)


 Node JS
 Python (pip install AWSIoTPythonSDK)
 Java
 …
 Set up your client with SDK and the
certificates

9/17/20 38
Some Notes
 1. Copy the certificates/keys to your real thing

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

Host(Endpoint)
 3. Set up your configuration of the code with SDK

Change your code


accordingly!
9/17/20 39
SDK and Demo Codes
 https://github.com/aws/aws-iot-device-sdk-python
 https://github.com/aws/aws-iot-device-sdk-
python/blob/master/samples/basicPubSub/basicPubSub.
py

40
More: Rule Engine, Link with SNS services
 Simple Notification
Service AWS IoT

Publish
Virtual “Thing”
EC2 t2.micro
/ Shadow

AWS
Forward

Subscribe
Topic:
CSE521_Tutoria
l

Subscribe Amazon SNS


9/17/20 41
Create a Rule in Amazon IoT
 Add a query to filter your interesting topic (event)

 Add an Action:
 Forward this message to SNS
 Specify Dest ARN
 Enable Rule

9/17/20 42
Notification on SMS & Email

9/17/20 43
One More Thing: Account Security
 DON’T UPLOAD YOUR KEY
PUBLICLY!!!

Time to Open Source!

9/17/20 44
Source: WeChat Subscriptions: 西乔《神秘的程序员们 39 》 Geek Life Chpt
What if… $50,000 AWS Bill!

9/17/20 45
Source: 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
Some project examples
 Gesture recognition with smartwatch
 Recognize the specific gesture to control the light

 Smart pet feeder


 Food dispenser with schedules and smart control

 Smart mirror
 Show personalized info in the mirror

Sensing, Connecting, Smart

If you have any question about the project,


feel free to send me an Email
46
Thanks!

Ruixuan Dai

You might also like