Cloud Tutorial: AWS IoT CSE 520S Spring, Jan. 16, 2020 Ruixuan 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 q 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 … 3 1/16/20
Cloud Services: On-premise Software Ø Traditional APP Data Ø installed and runs on personal computer Runtime Middleware Ø You Manage and Deploy You Manage q Hardware OS q OS q Software Virtualization Server Ø Example q This presentation Storage Network 4 1/16/20
Infrastructure as a Service (IaaS) Ø IaaS APP q "physical server box” Web q Virtual Machine Service Data You Manage • Memory Runtime • Storage • CPU Middleware • Network OS Ø Example Service Provider Manages q AWS EC2 Virtualization q AWS EFS Server Storage Ø Use case q Build up you VM cluster Network 5 1/16/20
Platform as a Service (PaaS) You Manage Ø PaaS APP q You get a framework Data q Host Application q Tools Runtime Middleware Service Provider Manages Ø Example OS q AWS IoT Virtualization Ø Use case Server q Build up you’re smart A/C Storage controller Network 6 1/16/20
PaaS Example: AWS IoT Tools Framework The essence is MESSAGING MIDDLEWARE Send messages between sensors and servers… 7 1/16/20
Software as a Service (SaaS) Ø SaaS APP q You get a whole solution Data Service Provider Manages Runtime Ø Example Middleware q Gmail OS q Dropbox Virtualization q Office365 Server Storage Network 8 1/16/20
XaaS: A Recap PaaS On-Premise IaaS SaaS You Manage APP APP APP APP Data Data Data Data You Manage Runtime Runtime Runtime Runtime Service Provider Manages Middleware Middleware Middleware Middleware Service Provider Manages 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 1/16/20
Tutorial: Hello! AWS IoT!!
Internet-of-Things Ø 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 11 1/16/20 Source: https://aws.amazon.com/iot-platform/ http://www.brain-smart.net/smart-brain-health-blog/page/2/#axzz4W4oSp8a6
Solution: AWS IoT Smart: Other Cloud Service United: Connect + Communication Data Storage Stated: “Thing Shadow” Machine Learning 12 1/16/20 Source: https://aws.amazon.com/iot-platform/
Tutorial: Hello AWS IoT! Forward Publish Amazon SNS Subscribe Temperature sensor Period: 5s (0.2Hz) Message middleware 13 1/16/20 Source: https://aws.amazon.com/iot-platform/
Pointers Ø Amazon IoT q http://docs.aws.amazon.com/iot/latest/developerguide/what-is- aws-iot.html Ø Raspberry Pi q https://www.raspberrypi.org/ Ø Resource list for course projects q 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
Get into AWS Manage Console Ø Create your own AWS account Ø Sign In IoT Manage Console q https://aws. amazon .com/ iot / 15 1/16/20
Step 1: Create a Virtual "Thing” Ø 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 A “Dashboard” to show some info q Shadow is a special topic in AWS IoT Ø Certificates and policy AWS IoT q Authentication, Security q Permission and roles Certificates -> your ID Virtual Policy -> your permission book “Thing” / Shadow 16 1/16/20
Create a thing Ø 1. AWS IoT Menu • Things è Create Ø 2. Give a name 17 1/16/20
18
19
The keys and cert will be used later 20
Create Policy Ø A policy is attached to a key/cert q It tells what this key/cert can do 21
22
This is the policy you created 23
Attach Policy Ø Attach Policy to the key/cert q A policy tells what this key/cert can do Click the cert 24
25
26
AWS Things Summary q Shadow: Store/retrieve some information q Certificate: authenticate the device q Policy: define the roles/permissions of the certificate 27
Let’s test it online!
Basic Interact: Publish to the “Shadow” Ø Get your “Shadow” q In your Thing Page Shadow Topic 29 1/16/20
Find your “Shadow” Topic Ø Topic: can be seen as the “address” Shadow Topic 30 1/16/20
Ø Using Embedded Test Client to Test q In AWS IoT Page Your Shadow Topic Topic Message 31 1/16/20
Shadow Message { "state": { "reported":{ "time":"13:45", "temperature":"25"} }, "message": "Hello from AWS IoT 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 32
Update Shadow Ø In your “Thing” Page 33
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 34 1/16/20
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 I am going to publish a tweet. “Today is beautiful ” Twitter account a “Topic” Received message from Trump: Subscriber “Today is beautiful” Publisher 35 1/16/20
Step 2: Connect a “Physical” Device AWS IoT AWS IoT SDK AWS SDK Client Certificate Attach Virtual “Thing” / Shadow Temperature sensor Period: 15s (4Hz) Copy Policy 36 1/16/20
Connect your Device Ø Copy certificates to your physical things q Note: through scp utility q Downloaded before! Ø Choose your AWS SDK (support MQTT) q Node JS q Python ( pip install AWSIoTPythonSDK ) q Java q … Ø Set up your client with SDK and the certificates 37 1/16/20
Some Notes Ø 1. Copy the certificates/keys to your real thing Ø 2. You will need the endpoint and port (8883) Host(Endpoint) Modify the code 38 1/16/20
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 39
More: Rule Engine, Link with SNS services Ø Simple Notification Service AWS IoT Publish Virtual “Thing” / EC2 t2.micro Shadow AWS Forward Subscribe Topic: CSE521_Tutorial Subscribe Amazon SNS 40 1/16/20
Create a Rule in Amazon IoT Ø 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 41 1/16/20
Notification on SMS & Email 42 1/16/20
One More Thing: Account Security Ø DON’T UPLOAD YOUR KEY PUBLICLY!!! Time to Open Source! 43 1/16/20 Source: WeChat Subscriptions: 西乔《神秘的程序员们 39 》 Geek Life Chpt 39.
What if… $50,000 AWS Bill! 44 1/16/20 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
Project 0: AWS IoT Ø 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
Some project examples Ø Gesture recognition with smartwatch q Recognize the specific gesture to control the light Ø Smart pet feeder q Food dispenser with schedules and smart control Ø Smart mirror q 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
Recommend
More recommend