aws iot button and lambda to power a blockchain project - aws serverless web day

35
June 2016 AWS IoT+ Lambda to power a blockchain project by Johann Romefort

Upload: aws-germany

Post on 10-Jan-2017

714 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

June 2016

AWS IoT+ Lambda to

power a blockchain project

by Johann Romefort

Page 2: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

About Johann

• Tech Evangelist @Stylight

• 15+ years in tech

• In Germany for 2 years

• 7 years in San Francisco

doing startups

• Organizer of many meetups

2

Page 3: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Agenda

3

• Overview of the project & constraints

• Configure your AWS IoT Button

• Introduction to AWS IoT

• The MQTT Client

• Connecting it to Lambda

Page 4: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Technologies involved

4

• AWS IoT

• Lambda

• SQS

• Node.JS

• Ethereum

Page 5: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Overview of the project

5

• Creation of a digital certificate of attendance on the

blockchain

• Minimal UI and input mechanism

• Scan ticket, Press button and done!

Page 6: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Project Diagram: 10000 feet overview

6

Page 7: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

7

1

2

3

scanTicket

getOrder

generateCertificate

4

5

writeToBlockchain

Project Diagram: 5000 feet overview

Page 8: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Project Constraints

8

• Should run on local computer with no access possible from

outside

• No access to keyboard or touch screen

• Certificate should be easy to verify, impossible to fake,

permanent

• Serverless

Page 9: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

The Live Setup

• MacBook Pro running

local blockchain node

• AWS IoT button for user

input

Page 10: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What is Blockchain?

• Blockchain is the technology behind Bitcoin

• Bitcoin was created in 2008 by Satoshi Nakamoto

• Blockchain is literally a chain of blocks.

• A blockchain is immutable – no one can change

the data once it’s been written on the chain.

Page 11: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What is Blockchain?

Page 12: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What can I do with an immutable

distributed ledger?

• Cryptocurrencies

• Property titles

• Notarised acts

• Digital Certificates

• And more…

Page 13: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Why AWS IoT, Button and Lambda +

SQS?

13

• Simpler input command / device one can think about

• Very simple setup

• Communication with SQS allows for a simple client

running inside a firewall and subscribing to a queue

topic in the cloud

Page 14: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

AWS IoT Button• Programmable version of the

Dash Button

• Easy Wifi configuration

• Connect directly to AWS IoT

• Interactions:

• Normal press

• Long press

• Double press

14

Page 15: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Configure your AWS IoT Button

15

Page 16: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Connect to button WIFI

network

16

Page 17: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Introduction to AWS IoT

17

• Serverless way to connect your IoT devices and start

processing data

• Supports MQTT, HTTP

• Secure - communication through use of X.509 Certificates

• Can connect huge amount of sensors, store and process the

data in real-time

Page 18: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

AWS IoT Architecture

18source: http://docs.aws.amazon.com/iot/latest/developerguide/aws-iot-how-it-works.html

Page 19: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Source: https://aws.amazon.com/iot/how-it-works/

Page 20: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What’s a Thing?

20

• An IoT Device

• Eg: Intel Edison, Arduino Yun + sensors / actuators

• In our case an AWS IoT button

Page 21: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What’s the Message Broker?

21

• Used to securely exchange messages following the publish-

subscribe pattern, between IoT applications and Things.

• MQTT to publish/subscribe

• HTTP to publish

Page 22: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What’s the Rule Engine?

22

• Used to process messages and talk to other

AWS components like Lambda, DynamoDB,

etc

• SQL-Based language to select specific

messages to be passed along.

Page 23: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What are Thing Shadows?

23

• Devices sometimes go offline

• A Thing Shadow provide a persistent

representation of a Thing

• A Thing can sync its state to its Thing

Shadow

Page 24: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

AWS IoT Console

24

Page 25: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Let’s look at the MQTT Client

25

• Message Queue Telemetry

Transport

• A lightweight publish-subscribe

messaging protocol for small

sensors and mobile devices,

optimized for high-latency or

unreliable networks

Page 26: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

MQTT Client

26

• Generate ClientID

• Subscribe to topic iotbutton/+

• Press the button

• Watch event flowing

Page 27: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Don’t have a AWS IoT Button?

27

• Just use the MQTT Client to simulate a

payload

Page 28: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

What do we want to do?

28

• Use the button as input device to validate the transaction

on the blockchain - Writing the transaction is a permanent

operation, certificate will be available forever.

• Send a SQS message to a topic our client is listening to.

Page 29: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Create your SQS Queue

29

Page 30: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Writing the Lambda

30

Page 31: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Configure the Policy Document

31

{

"Version": "2012-10-17",

"Statement": [

{

"Effect": "Allow",

"Action": [

"logs:CreateLogGroup",

"logs:CreateLogStream",

"logs:PutLogEvents"

],

"Resource": "arn:aws:logs:*:*:*"

},

{

"Action": [

"sqs:SendMessage",

"sqs:GetQueueUrl"

],

"Effect": "Allow",

"Resource": "arn:aws:sqs:us-west-2:882247834355:buttonPressed"

}

]

}

Page 32: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Testing our Lambda

32

• Write client

code to listen to

SQS

• Use either AWS

IoT Button or

MQTT to test

the whole chain

Page 33: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Testing our Lambda

Page 34: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Going further

34

• We don’t need lambda!

• We can use SQS directly from

AWS IoT Rule Engine

Page 35: AWS IoT Button and Lambda to power a blockchain project - AWS Serverless Web Day

Questions?

Follow me on twitter: @romefort

Check our blog: tech.stylight.com