Slide 1

Slide 1 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Adrian Hornsby, Cloud Architecture Evangelist Building Serverless Interactive Apps @adhorn

Slide 2

Slide 2 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Slide 3

Slide 3 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Real-Time Analytics Internet of Things Machine Learning

Slide 4

Slide 4 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Real-time streaming

Slide 5

Slide 5 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Stream New Data in Seconds Get actionable insights quickly Streaming Ingest video & data as it’s generated Process data on the fly Real-time analytics/ML, alerts, actions

Slide 6

Slide 6 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Producers Consumers Shard 1 Shard 2 Shard n Shard 3 … … Write: 1MB Read: 2MB ** A shard is a group of data records in a stream Amazon Kinesis

Slide 7

Slide 7 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Streaming data in the cloud with Kinesis

Slide 8

Slide 8 text

Data for Competitive Advantage

Slide 9

Slide 9 text

S3 → EMR→ Supercell: Data collection and processing DynamoDB ElasticSearch

Slide 10

Slide 10 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Clash Royal: Getting relevant value for the players

Slide 11

Slide 11 text

Real-time Analytics Demo http://quad.adhorn.me

Slide 12

Slide 12 text

Real-time analytics Amazon Kinesis Stream Amazon Kinesis Analytics Amazon Cognito Amazon Kinesis Stream Amazon DynamoDB Amazon Lambda Amazon S3 JavaScript SDK

Slide 13

Slide 13 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Data Input Source JSON Data • Once per second, using JavaScript SDK: • Unique Cognito ID (anonymous user) • OS • Quadrant • Data sent to Kinesis Stream Amazon Kinesis Stream Amazon Cognito Amazon S3 JavaScript SDK { "recordTime": 1486505943.204, "cognitoId": "us-east-1:3626e211-d2a3-447b-8231-e1f4e0486f44", "os": "Android", "quadrant": "A”, … }

Slide 14

Slide 14 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How is raw data mapped to a schema? Amazon Kinesis stream Amazon Kinesis Analytics cognitoID os quadrant Android A iOS B Source Data for Kinesis Analytics { "recordTime": 1486505943.204, "cognitoId": "us-east-1:", "os": "Android", "quadrant": "A" }

Slide 15

Slide 15 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How is streaming data accessed with SQL? STREAM • Analogous to a TABLE • Represents continuous data flow CREATE OR REPLACE STREAM DISTINCT_USER_STREAM( COGNITO_ID VARCHAR(64), DEVICE VARCHAR(32), OS VARCHAR(32), QUADRANT char(1), DT TIMESTAMP);

Slide 16

Slide 16 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How is streaming data accessed with SQL? PUMP • Continuous INSERT query • Inserts data from one in-application stream to another CREATE OR REPLACE PUMP "DISTINCT_USER_PUMP" AS INSERT INTO "DISTINCT_USER_STREAM" SELECT STREAM DISTINCT "cognitoId", ...

Slide 17

Slide 17 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How do we model our data? DISTINCT_USERS_STREAM •COGNITO_ID •OS •QUADRANT •DT DESTINATION_SQL_STREAM •UNIQUE_USER_COUNT •ANDROID_COUNT •IOS_COUNT •OTHER_OS_COUNT •QUADRANT_A_COUNT •QUADRANT_B_COUNT •QUADRANT_C_COUNT •QUADRANT_C_COUNT SOURCE_STREAM •cognitoID •os •quadrant Kinesis stream Kinesis Stream Pump Kinesis Analytics Application

Slide 18

Slide 18 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How do we get distinct user records? Use PUMP to insert distinct records into in-app STREAM CREATE OR REPLACE PUMP "DISTINCT_USER_PUMP" AS INSERT INTO "DISTINCT_USER_STREAM" SELECT STREAM DISTINCT "cognitoId", "device", "os", "quadrant", FLOOR(s.ROWTIME TO SECOND) FROM "SOURCE_SQL_STREAM_001" s; DISTINCT_USERS_STREAM •COGNITO_ID •OS •QUADRANT •DT SOURCE_STREAM •cognitoID •os •quadrant

Slide 19

Slide 19 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How do we aggregate per second? • Tumbling window, group by time period CREATE OR REPLACE PUMP "OUTPUT_PUMP" AS INSERT INTO "DESTINATION_SQL_STREAM" SELECT STREAM COUNT(dus.COGNITO_ID) AS UNIQUE_USER_COUNT, COUNT((CASE WHEN dus.OS = 'Android' THEN COGNITO_ID ELSE null END)) AS ANDROID_COUNT, COUNT((CASE WHEN dus.OS = 'iOS' THEN COGNITO_ID ELSE null END)) AS IOS_COUNT, COUNT((CASE WHEN dus.OS = 'Windows Phone' THEN COGNITO_ID ELSE null END)) AS WINDOWS_PHONE_COUNT, COUNT((CASE WHEN dus.OS = 'other' THEN COGNITO_ID ELSE null END)) AS OTHER_OS_COUNT, COUNT((CASE WHEN dus.QUADRANT = 'A' THEN COGNITO_ID ELSE null END)) AS QUADRANT_A_COUNT, COUNT((CASE WHEN dus.QUADRANT = 'B' THEN COGNITO_ID ELSE null END)) AS QUADRANT_B_COUNT, COUNT((CASE WHEN dus.QUADRANT = 'C' THEN COGNITO_ID ELSE null END)) AS QUADRANT_C_COUNT, COUNT((CASE WHEN dus.QUADRANT = 'D' THEN COGNITO_ID ELSE null END)) AS QUADRANT_D_COUNT, ROWTIME FROM "DISTINCT_USER_STREAM" dus GROUP BY FLOOR(dus.ROWTIME TO SECOND);

Slide 20

Slide 20 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Comparing Types of Windows • Output created at the end of the window • The output of the window will be single event based on the aggregate function used Tumbling window Aggregate per time interval Sliding window Windows constantly re-evaluated

Slide 21

Slide 21 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Output to Kinesis Stream MENTION_COUNT_STREAM •UNIQUE_USER_COUNT •ANDROID_COUNT •… Amazon Kinesis Stream { "unique_user_count": 96, "android_count": 50, "ios_count": 46, "android_count": 50, "quadrant_a_count": 80, "quadrant_b_count ": 10, "quadrant_c_count ": 3, "quadrant_d_count ": 3 } 1 record, every second

Slide 22

Slide 22 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Persist aggregated data in DynamoDB Kinesis Stream Lambda DynamoDB event.Records.forEach((record) => { const payload = new Buffer(record.kinesis.data, 'base64').toString('ascii'); var docClient = new AWS.DynamoDB.DocumentClient(); var table = "user-quadrant-data"; var data = JSON.parse(payload); var params = { TableName: table, Item:{ "dataType": "quadrantRollup", "windowtime": (new Date(data.WINDOW_TIME)).getTime(), "userCount": data.UNIQUE_USER_COUNT, "quadrantA": data.QUADRANT_A_COUNT, "quadrantB": data.QUADRANT_B_COUNT, ... } }; docClient.put(params, function(err, data) { ... Lambda event source mapping

Slide 23

Slide 23 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Processing a Kinesis Streams with AWS Lambda Shard 1 Shard 2 Shard 3 Shard 4 Shard n Kinesis Stream . . . . . . • Single instance of Lambda function per shard • Polls shard once per second • Lambda function instances created and removed automatically as stream is scaled Gets Records 1x per sec 10k records

Slide 24

Slide 24 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Internet of Things

Slide 25

Slide 25 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Registry: Identity for devices Rules and Actions: Match patterns and take actions Shadows: Virtual representation of the device in the cloud. {Thing Name, Sensor Temp, , GetTemp(), Output LED} Rules Engine Shadow Registry Amazon S3, AWS Lambda, Kinesis DynamoDB SNS Elasticsearch Machine Learning Mobile App AWS IoT: Key features

Slide 26

Slide 26 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Secure by Default: Connect securely via X509 Certs and TLS v1.2 Client Mutual Auth Multi-protocol Message Gateway: MQTT, HTTP or WebSockets. Elastic Pub Sub Broker: from 1 to 1-billion long-lived connections with zero provisioning Subscribers Publishers AWS IoT: Key features

Slide 27

Slide 27 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Sensor data collection IoT rules IoT actions MQTT Amazon S3: Raw records Amazon Kinesis Firehose: Delivery stream Amazon S3: Batched records Amazon Kinesis Streams: Real-time stream AWS IoT: Data collection IoT Sensors Real-time analytics applications

Slide 28

Slide 28 text

http://bit.ly/adhornlightbulb

Slide 29

Slide 29 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS IoT IoT shadow Amazon Cognito MQTT over WebSockets AWS Lambda Alexa Amazon S3 Interactive Serverless applications

Slide 30

Slide 30 text

http://bit.ly/adhorncolorcube

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Machine Learning

Slide 33

Slide 33 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. FRAMEWORKS AND INTERFACES PLATFORM SERVICES APPLICATION SERVICES Amazon Rekognition Amazon Polly Amazon Lex Machine Learning on AWS Amazon Rekognition Video Amazon Transcribe Amazon Comprehend Amazon SageMaker AWS DeepLens Amazon EMR Deep Learning AMI Amazon Translate

Slide 34

Slide 34 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Amazon Rekognition Deep Learning-based image analysis service

Slide 35

Slide 35 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Object & Scene Detection

Slide 36

Slide 36 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Facial Analysis

Slide 37

Slide 37 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Crowd Detection – up to 100 faces

Slide 38

Slide 38 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Facial Search

Slide 39

Slide 39 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Text in Image

Slide 40

Slide 40 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Marinus Analytics uses facial recognition to stop human trafficking “Now with Traffic Jam’s FaceSearch, powered by Amazon Rekognition, investigators are able to take effective action by searching through millions of records in seconds to find victims.” http://www.marinusanalytics.com/articles/2017/10/17/amazon-rekognition-helps-marinus-analytics-fight-human-trafficking

Slide 41

Slide 41 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Rekognition API example aws rekognition detect-labels –-image '{"S3Object":{"Bucket":"adhorn-reko","Name":"horse.jpg"}}' { "Labels": [ { "Confidence": 99.29136657714844, "Name": "Human" }, { "Confidence": 99.29136657714844, "Name": "People" }, { "Confidence": 99.29136657714844, "Name": "Person" }, ……

Slide 42

Slide 42 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Rekognition API example aws rekognition detect-faces --image '{"S3Object":{"Bucket":"adhorn-reko","Name":"horse.jpg"}}' --attributes "ALL” { "FaceDetails": [ { "BoundingBox": { "Width": 0.05462963134050369, "Top": 0.2880098819732666, "Left": 0.4722222089767456, "Height": 0.07292954623699188 }, "Landmarks": [ { "Y": 0.31606796383857727, "X": 0.48852023482322693, "Type": "eyeLeft" ………

Slide 43

Slide 43 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Amazon Polly Deep Learning-based text-to-speech service

Slide 44

Slide 44 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Polly “What's the difference between a hippo and a zippo? One is really heavy, and the other is a little lighter.” Amazon Polly: Text In, Life-like Speech Out

Slide 45

Slide 45 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. The price of this book is 45€ A Focus On Voice Quality & Pronunciation Support for Speech Synthesis Markup Language (SSML) Version 1.0 https://www.w3.org/TR/speech-synthesis

Slide 46

Slide 46 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Polly API example aws polly synthesize-speech --text "It was nice to live such a wonderful live show" --output-format mp3 --voice-id Joanna --text-type text johanna.mp3 aws polly synthesize-speech --text-type ssml --text file://ssml_polly --output-format mp3 --voice-id Joanna speech.mp3

Slide 47

Slide 47 text

http://poliko.adhorn.me

Slide 48

Slide 48 text

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Demo – ML services (CLI) + Poliko https://github.com/adhorn/poliko