Slide 1

Slide 1 text

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Danilo Poccia, Technical Evangelist @danilop Serverless for Developers Tips for Your Next App

Slide 2

Slide 2 text

@AWSStartups #AWSLoft

Slide 3

Slide 3 text

What is Serverless?

Slide 4

Slide 4 text

Lambda Function Trigger Do whatever you want: It’s Your Code!

Slide 5

Slide 5 text

Lambda Function Trigger Do whatever you want: It’s Your Code! S3 Bucket Amazon API Gateway DynamoDB Table AWS IoT Rule Much More! Amazon CloudWatch

Slide 6

Slide 6 text

Lambda Function You can “chain” events to build Event-Driven Applications S3 Bucket DynamoDB Table Lambda Function

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

{ "resource": "Resource path", "path": "Path parameter", "httpMethod": "Incoming request's method name" "headers": {Incoming request headers} "queryStringParameters": {query string parameters } "pathParameters": {path parameters} "stageVariables": {Applicable stage variables} "requestContext": {Request context, including authorizer-returned key-value pairs} "body": "A JSON string of the request payload." "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode" } { “statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... }, "body": “...", "isBase64Encoded": true|false } Output Format of a Lambda Function for Proxy Integration Input Format of a Lambda Function for Proxy Integration

Slide 14

Slide 14 text

Let’s build a Web Chat…

Slide 15

Slide 15 text

Web Browser

Slide 16

Slide 16 text

Web Browser CloudFront Edge Location S3 Bucket HTTPS Static Content (HTML, CSS, JS)

Slide 17

Slide 17 text

Web Browser CloudFront Edge Location S3 Bucket HTTPS Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS)

Slide 18

Slide 18 text

Web Browser CloudFront Edge Location S3 Bucket Amazon API Gateway Lambda Function(s) DynamoDB Table(s) HTTPS Dynamic Content Database Access Execute Functions Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS)

Slide 19

Slide 19 text

Web Browser CloudFront Edge Location S3 Bucket Amazon API Gateway Lambda Function(s) DynamoDB Table(s) AWS IoT Topic(s) HTTPS Dynamic Content Database Access MQTT over Secure WebSockets (Publish, Subscribe) Execute Functions Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS)

Slide 20

Slide 20 text

Web Browser CloudFront Edge Location S3 Bucket Amazon API Gateway Lambda Function(s) DynamoDB Table(s) AWS IoT Topic(s) AWS IoT Rule(s) HTTPS Dynamic Content Database Access MQTT over Secure WebSockets (Publish, Subscribe) Subscribe Republish Execute Functions Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS)

Slide 21

Slide 21 text

Web Browser CloudFront Edge Location S3 Bucket Amazon API Gateway Lambda Function(s) DynamoDB Table(s) AWS IoT Topic(s) AWS IoT Rule(s) HTTPS Dynamic Content Database Access MQTT over Secure WebSockets (Publish, Subscribe) Subscribe Republish Execute Functions Execute Functions Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS) Publish

Slide 22

Slide 22 text

Web Browser CloudFront Edge Location S3 Bucket Amazon API Gateway Lambda Function(s) DynamoDB Table(s) AWS IoT Topic(s) AWS IoT Rule(s) HTTPS Dynamic Content Database Access MQTT over Secure WebSockets (Publish, Subscribe) Subscribe Republish Execute Functions Write to DynamoDB Execute Functions Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS) Publish

Slide 23

Slide 23 text

Web Browser CloudFront Edge Location S3 Bucket Amazon API Gateway Lambda Function(s) DynamoDB Table(s) AWS IoT Topic(s) AWS IoT Rule(s) Kinesis Stream(s) HTTPS Dynamic Content Database Access MQTT over Secure WebSockets (Publish, Subscribe) Subscribe Republish Execute Functions Streaming Data Write to DynamoDB Execute Functions Execute Functions (Micro-Batches) Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS) Publish

Slide 24

Slide 24 text

Web Browser CloudFront Edge Location S3 Bucket Amazon API Gateway Lambda Function(s) DynamoDB Table(s) AWS IoT Topic(s) AWS IoT Rule(s) Kinesis Stream(s) HTTPS Dynamic Content Database Access MQTT over Secure WebSockets (Publish, Subscribe) Subscribe Republish Execute Functions Streaming Data Write to DynamoDB Execute Functions Execute Functions (Micro-Batches) Amazon Cognito Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS) Publish

Slide 25

Slide 25 text

What about Topics & Rules?

Slide 26

Slide 26 text

Web Browser AWS IoT Topics chat/in/${iot:ClientId} chat/out chat/pub/${room} chat/stream $aws/events/# Each client has a secure “input” topic to receive content from the back end All client can publish on an “output” topic, they are recognizable by their clientId All client can subscribe and receive from “public” topics Another “output” topic optimized for high volumes AWS IoT Lifecycle Events

Slide 27

Slide 27 text

Web Browser AWS IoT Topics AWS IoT Rules chat/in/${iot:ClientId} chat/out chat/pub/${room} chat/stream $aws/events/# Each client has a secure “input” topic to receive content from the back end All client can publish on an “output” topic, they are recognizable by their clientId All client can subscribe and receive from “public” topics Another “output” topic optimized for high volumes AWS IoT Lifecycle Events Lambda function to process important messages, such as a new client connection Republish rule to send messages to the corresponding room public topic Lambda function to process high volume dreaming data Kinesis Stream to manage high volume streaming data Lambda function to process AWS IoT Lifecycle Events Store all messages in a database, to be sent to the client on connection

Slide 28

Slide 28 text

Web Browser AWS IoT Topics AWS IoT Rules chat/in/${iot:ClientId} chat/out chat/pub/${room} chat/stream $aws/events/# Each client has a secure “input” topic to receive content from the back end All client can publish on an “output” topic, they are recognizable by their clientId All client can subscribe and receive from “public” topics Another “output” topic optimized for high volumes AWS IoT Lifecycle Events Lambda function to process important messages, such as a new client connection Republish rule to send messages to the corresponding room public topic Lambda function to process high volume dreaming data Kinesis Stream to manage high volume streaming data Lambda function to process AWS IoT Lifecycle Events Store all messages in a database, to be sent to the client on connection You can use this topic to inject JavaScript code in the browser

Slide 29

Slide 29 text

So how does the flow look like?

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Demo https://chat.danilop.net/SFLoft Code https://github.com/danilop/serverless-chat

Slide 38

Slide 38 text

What next?

Slide 39

Slide 39 text

https://aws.amazon.com/serverless http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html http://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html

Slide 40

Slide 40 text

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Danilo Poccia, Technical Evangelist @danilop Thank You!