Serverless for Developers

Serverless for Developers

AWS Pop-up Loft, San Francisco, July 28th, 2017

Building a real-time web chat using AWS Lambda, AWS IoT (for WebSockets) and Amazon DynamoDB (with TTL and Auto Scaling).

7c9b8b368924556d8642bdaed3ded1f5?s=128

Danilo Poccia

July 28, 2017
Tweet

Transcript

  1. 1.

    © 2016, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Danilo Poccia, Technical Evangelist @danilop Serverless for Developers Tips for Your Next App
  2. 5.

    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
  3. 7.
  4. 8.
  5. 9.
  6. 10.
  7. 11.
  8. 12.
  9. 13.

    { "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
  10. 17.

    Web Browser CloudFront Edge Location S3 Bucket HTTPS Amazon Cognito

    Authentication (AWS Temporary Credentials) Static Content (HTML, CSS, JS)
  11. 18.

    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)
  12. 19.

    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)
  13. 20.

    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)
  14. 21.

    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
  15. 22.

    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
  16. 23.

    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
  17. 24.

    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
  18. 26.

    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
  19. 27.

    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
  20. 28.

    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
  21. 30.
  22. 31.
  23. 32.
  24. 33.
  25. 34.
  26. 35.
  27. 36.
  28. 40.

    © 2016, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Danilo Poccia, Technical Evangelist @danilop Thank You!