Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building a serverless “positive chat” and why p...

Danilo Poccia
September 19, 2019

Building a serverless “positive chat” and why products and teams are important

AWS User Group, Colombo, September 19th, 2019

I wanted to build something to improve the way we communicate, a 'positive chat' that rejects sentences with negative sentiment and translates messages to be more inclusive. As I was building, I thought: What are the issues for serverless developments? What about teams? This session is the result.

Danilo Poccia

September 19, 2019
Tweet

More Decks by Danilo Poccia

Other Decks in Programming

Transcript

  1. © 2019, Amazon Web Services, Inc. or its Affiliates. Danilo

    Poccia Principal Evangelist, Serverless @danilop Building a serverless “positive chat” and why products and teams are important
  2. © 2019, Amazon Web Services, Inc. or its Affiliates. HTTP

    protocol Client Server Request Response
  3. © 2019, Amazon Web Services, Inc. or its Affiliates. WebSockets

    protocol GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 Origin: http://example.com HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat Client Server Request Response WebSocket
  4. © 2019, Amazon Web Services, Inc. or its Affiliates. Serverless

    Real-Time Apps – There are a few options • AWS IoT Core without physical devices • MQTT pub/sub • AWS AppSync • GraphQL subscriptions • Amazon API Gateway • WebSocket connections New
  5. © 2019, Amazon Web Services, Inc. or its Affiliates. Amazon

    API Gateway – WebSocket APIs Amazon API Gateway Connect function Web browser AWS Cloud Region WebSocket connection (stateful) Disconnect Connect By Route Key(s) Default Disconnect function Route Key function(s) Default function API Gateway integration (stateless) SigV4 POST @ConnectionId ConnectionId ConnectionId
  6. © 2019, Amazon Web Services, Inc. or its Affiliates. Serverless

    Real-Time Apps – What to build? • Building a chat is the mandatory example for WebSockets • Can I build something that can help in being a “better” person? • Not in person communication is hard • Can machine learning help? Some services are super easy to use!
  7. © 2019, Amazon Web Services, Inc. or its Affiliates. FRAMEWORKS

    AND INTERFACES ML for data scientists KERAS Frameworks Interfaces APPLICATION SERVICES ML for everyone PLATFORM SERVICES ML for engineers NVIDIA Tesla V100 GPUs (14x faster than P2) Machine Learning AMIs INFRASTRUCTURE Powering the ML Intel Xeon Skylake (Optimized for ML) A W S G R E E N G R A S S M L L E X P O L L Y R E K O G N I T I O N I M A G E & V I D E O T R A N S C R I B E T R A N S L A T E C O M P R E H E N D F O R E C A S T P E R S O N A L I Z E A M A Z O N S A G E M A K E R A W S D E E P L E N S S A G E M A K E R G R O U N D T R U T H & M E C H A N IC A L T U R K S P A R K & E M R
  8. © 2019, Amazon Web Services, Inc. or its Affiliates. Let’s

    build a “Positive Chat” J • Avoid negative sentiment • Reject negative sentences • Positive sentiment gamification • Automatically translate between different languages • Extract message topics to improve searchability and discoverability • Create and update a chat room “tag cloud” • Search or filter messages by “tag”
  9. © 2019, Amazon Web Services, Inc. or its Affiliates. Let’s

    build a “Positive Chat” J • Attach images to messages • Moderate content • Describe image content (objects, people, emotions) • Find text in images • Anonymize people faces • For all people or based on estimated age • Cover faces with emoticon based on actual emotions To D o
  10. © 2019, Amazon Web Services, Inc. or its Affiliates. Positive

    Chat – Serverless architecture Amazon DynamoDB Amazon Cognito Amazon API Gateway WebSocket connection PositiveChat Lambda function Connections table Conversations table Topics table Web browser AWS Cloud S3 bucket for static assets (HTML, CSS, JS) Authentication Authorization To be implemented Amazon Comprehend Amazon Translate Amazon Rekognition To be implemented
  11. © 2019, Amazon Web Services, Inc. or its Affiliates. AWS

    Serverless Application Model (SAM) AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetFunction: Type: AWS::Serverless::Function Properties: Handler: index.get Runtime: nodejs8.10 CodeUri: src/ Policies: - DynamoDBReadPolicy: TableName: !Ref MyTable Events: GetResource: Type: Api Properties: Path: /resource/{resourceId} Method: get MyTable: Type: AWS::Serverless::SimpleTable Just 20 lines to create: • Lambda function • IAM role • API Gateway • DynamoDB table O pen Source
  12. © 2019, Amazon Web Services, Inc. or its Affiliates. Use

    SAM CLI to package and deploy SAM templates pip install --user aws-sam-cli # Or use Linux/Windows/macOS installers sam init --name my-app --runtime python cd my-app/ sam local ... # generate-event/invoke/start-api/start-lambda sam validate # The SAM template sam build # Depending on the runtime sam package --s3-bucket my-packages \ --output-template-file packaged.yaml sam deploy --template-file packaged.yaml \ --stack-name my-stack-prod sam logs -n MyFunction --stack-name my-stack-prod -t # Tail logs sam publish # To the Serverless Application Repository O pen Source CodePipeline Use CloudFormation deployment actions with any SAM application Jenkins Use SAM CLI plugin
  13. © 2019, Amazon Web Services, Inc. or its Affiliates. Positive

    Chat Demo • https://github.com/danilop/serverless-positive-chat
  14. © 2019, Amazon Web Services, Inc. or its Affiliates. Positive

    Chat Demo • https://pcs.demo.danilop.net/ ?room=Colombo
  15. © 2019, Amazon Web Services, Inc. or its Affiliates. $

    wc -l positive-chat/app.js 326 positive-chat/app.js $ wc -l www/index.js 204 www/index.js backend + frontend ≃ 460 lines of code removing empty lines and comments
  16. © 2019, Amazon Web Services, Inc. or its Affiliates. ©

    2019, Amazon Web Services, Inc. or its Affiliates. What about teams? Photo by Perry Grone on Unsplash
  17. © 2019, Amazon Web Services, Inc. or its Affiliates. You

    Build It, You Run It “This brings developers into contact with the day-to-day operation of their software. It also brings them into day-to- day contact with the customer.” – Werner Vogels CTO, Amazon.com
  18. © 2019, Amazon Web Services, Inc. or its Affiliates. Team

    size & communication paths = ( − 1) 2 Communication paths in a team of N people
  19. © 2019, Amazon Web Services, Inc. or its Affiliates. Two

    pizza teams Photo by Kristina Bratko on Unsplash
  20. © 2019, Amazon Web Services, Inc. or its Affiliates. Separable

    vs complex tasks Separable task Complex task
  21. © 2019, Amazon Web Services, Inc. or its Affiliates. Ability

    as a collection of cognitive tools Adam Abilities = 5 { A, B, C, D, E } For example: A – mobile development on iOS B – back end development in Java C – data analytics in Python D – complex SQL queries E – …
  22. © 2019, Amazon Web Services, Inc. or its Affiliates. Ability

    as a collection of cognitive tools Adam Carl Betsy { C, D, G } Abilities = 5 Abilities = 4 Abilities = 3 { A, B, E, F } { A, B, C, D, E }
  23. © 2019, Amazon Web Services, Inc. or its Affiliates. Diversity

    bonus model – Team with best abilities Adam Carl Betsy { C, D, G } Abilities = 5 Abilities = 4 Abilities = 3 Team Abilities = 6 { A, B, E, F } { A, B, C, D, E }
  24. © 2019, Amazon Web Services, Inc. or its Affiliates. Diversity

    bonus model – Team with more cognitive tools Adam Carl Betsy { A, B, E, F } { A, B, C, D, E } { C, D, G } Abilities = 5 Abilities = 4 Abilities = 3 Team Abilities = 7
  25. © 2019, Amazon Web Services, Inc. or its Affiliates. No

    diversity, no bonus – Beware hiring managers Adam Carl Betsy { A, B, C, D } { A, B, C, D, E } { B, C, D } Abilities = 5 Abilities = 4 Abilities = 3
  26. © 2019, Amazon Web Services, Inc. or its Affiliates. Some

    cognitive tools must be learned in order Adam Carl Betsy { A, B, C, D } { A, B, C, D, E } { A, B, C } Abilities = 5 Abilities = 4 Abilities = 3
  27. © 2019, Amazon Web Services, Inc. or its Affiliates. 2,092

    people who worked on 474 musicals from 1945 to 1989 Small world networks & creativity AJS Volume 111 Number 2 (September 2005): 000–000 PROOF 1 ᭧ 2005 by The University of Chicago. All rights reserved. 0002-9602/2005/11102-0003$10.00 Thursday Oct 13 2005 11:31 AM AJS v111n2 090090 VSJ Collaboration and Creativity: The Small World Problem1 Brian Uzzi Northwestern University Jarrett Spiro Stanford University Small world networks have received disproportionate notice in di- verse fields because of their suspected effect on system dynamics. The authors analyzed the small world network of the creative artists who made Broadway musicals from 1945 to 1989. Based on original arguments, new statistical methods, and tests of construct validity, they found that the varying “small world” properties of the systemic- level network of these artists affected their creativity in terms of the financial and artistic performance of the musicals they produced. The small world network effect was parabolic; performance in- creased up to a threshold after which point the positive effects reversed. Creativity aids problem solving, innovation, and aesthetics, yet our un- derstanding of it is still forming. We know that creativity is spurred when diverse ideas are united or when creative material in one domain inspires or forces fresh thinking in another. These structural preconditions suggest 1 Our thanks go out to Duncan Watts; Huggy Rao; Peter Murmann; Ron Burt; Matt Bothner; Frank Dobbin; Bruce Kogut; Lee Fleming; David Stark; John Padgett; Dan Diermeier; Stuart Oken; Jerry Davis; Woody Powell; workshop participants at the University of Chicago, University of California at Los Angeles, Harvard, Cornell, New York University, the Northwestern University Institute for Complex Organizations (NICO); and the excellent AJS reviewers, especially the reviewer who provided a remarkable 15, single-spaced pages of superb commentary. We particularly wish to thank Mark Newman for his advice and help in developing and interpreting the bipartite-affiliation network statistics. We also wish to give very special thanks to the Santa Fe Institute for creating a rich collaborative environment wherein these ideas first emerged, and to John Padgett, the organizer of the States and Markets group at the Santa Fe Institute. Direct correspondence to Brian Uzzi, Kellog School of Man- agement, Northwestern University, Evanston, Illinois 60208. E-mail: [email protected]
  28. © 2019, Amazon Web Services, Inc. or its Affiliates. 1.

    Write less code, be serverless 2. Give teams ownership and autonomy 3. Minimize communication paths 4. Maximize different abilities 5. Mix new and existing relationships
  29. © 2019, Amazon Web Services, Inc. or its Affiliates. ©

    2019, Amazon Web Services, Inc. or its Affiliates. Thank you! @danilop Please give me your feedback